nixpkgs icon indicating copy to clipboard operation
nixpkgs copied to clipboard

nut: race condition on boot apparent regression from 25.11 to 26.05

Open kwinz opened this issue 6 months ago • 2 comments

Nixpkgs version

  • Beta (26.05)

Describe the bug

i have a Raspberry Pi with NixOS 26.05 running NUT to monitor my ups that is connected via USB. on reboot of the Raspberry NUT won't start with:

Mai 28 03:03:46 nixos-ups-cluster upsd[1156]: no listening interface available
Mai 28 03:03:46 nixos-ups-cluster upsd[1156]: no listening interface available
Mai 28 03:03:46 nixos-ups-cluster systemd[1]: upsd.service: Control process exited, code=exited, status=1/FAILURE
Mai 28 03:03:46 nixos-ups-cluster systemd[1]: upsd.service: Failed with result 'exit-code'.
Mai 28 03:03:46 nixos-ups-cluster systemd[1]: Failed to start Uninterruptible Power Supplies (Daemon).
Mai 28 03:03:46 nixos-ups-cluster systemd[1]: upsd.service: Consumed 515ms CPU time over 1.047s wall clock time, 15.3M memory peak, 9.2M read from disk.
Mai 28 03:03:46 nixos-ups-cluster systemd[1]: Starting Uninterruptible Power Supplies (Register all UPS)...
Mai 28 03:03:46 nixos-ups-cluster upsdrvctl[1158]: Network UPS Tools upsdrvctl - UPS driver controller 2.8.4 release
Mai 28 03:03:46 nixos-ups-cluster upsdrvctl[1159]: Network UPS Tools 2.8.4 release - Generic HID driver 0.67
Mai 28 03:03:46 nixos-ups-cluster upsdrvctl[1159]: USB communication driver (libusb 1.0) 0.50
Mai 28 03:03:46 nixos-ups-cluster upsdrvctl[1159]: libusb1: Could not open any HID devices: no USB buses (or devices) found
Mai 28 03:03:46 nixos-ups-cluster upsdrvctl[1159]: No matching HID UPS found
Mai 28 03:03:46 nixos-ups-cluster upsdrvctl[1159]: upsnotify: notify about state NOTIFY_STATE_STOPPING with libsystemd: was requested, but not running as a service unit now, will not spam more about it
Mai 28 03:03:46 nixos-ups-cluster upsdrvctl[1158]: Driver failed to start (exit status=1)

A subsequent manual restart upsd and upsdrv services and the NUT service starts working. On NixOS 25.11 I didn't have this problem. Apparently it's trying to start before the USB devices and the network interface are available.

Steps to reproduce

Install NUT on a Raspberry Pi 4B with NixOS 26.05. Try Monitoring a USB UPS with a config like this:


  networking = {
    hostName = "nixos-ups-cluster";
    interfaces.end0 = {
      ipv4.addresses = [{
        address = "192.168.198.180";
        prefixLength = 24;
      }];
    };
    defaultGateway = {
      address = "192.168.198.1";
    };

    # These options are unnecessary when managing DNS ourselves
    useDHCP = false;
    dhcpcd.enable = false;

    # Configure DNS servers manually (this example uses Cloudflare and Google DNS)
    # IPv6 DNS servers can be used here as well.
    nameservers = [
      "1.1.1.1"
      "8.8.8.8"
    ];
  };

  users = {
    users.nut = {
      isSystemUser = true;
      group = "nut";
      # it does not seem to do anything with this directory
      # but something errored without it, so whatever
      home = "/var/lib/nut";
      createHome = true;
    };
    groups.nut = { };
  };

  power.ups = {
    enable = true;
    mode = "netserver";
    # for upsd
    openFirewall = true;
    upsmon.enable = false;

    # remote upsc users that can connect to our upsd
      users.admin = {
	      instcmds = [ "ALL" ];
        # sudo chmod 600 /var/nutmonpass
        # sudo chown nut /var/nutmonpass
        passwordFile = "/var/nutmonpass";
    };

    upsd.listen = [
      {
        address = "192.168.198.180";
        port = 3493;
      }
    ];

    ups."clusterups" = {
      driver = "usbhid-ups";
      port = "auto";
      # no UTF-8 support apparently
      description = "Dell server cluster USV APC2200";
      directives = [
        "override.battery.charge.low = 20"
      ];
    };

  };

Expected behaviour

No race condition on reboot.

Screenshots

No response

Relevant log output

Mai 28 03:03:44 nixos-ups-cluster systemd[1]: Started Name Service Cache Daemon (nsncd).
Mai 28 03:03:44 nixos-ups-cluster systemd[1]: Reached target Preparation for Network.
Mai 28 03:03:44 nixos-ups-cluster systemd[1]: Reached target Host and Network Name Lookups.
Mai 28 03:03:44 nixos-ups-cluster systemd[1]: Reached target User and Group Name Lookups.
Mai 28 03:03:44 nixos-ups-cluster systemd[1]: Starting Extra networking commands....
Mai 28 03:03:44 nixos-ups-cluster systemd[1]: Condition check resulted in /dev/ttyS1 being skipped.
Mai 28 03:03:45 nixos-ups-cluster systemd[1]: Stopped target Host and Network Name Lookups.
Mai 28 03:03:45 nixos-ups-cluster systemd[1]: Stopping Host and Network Name Lookups...
Mai 28 03:03:45 nixos-ups-cluster systemd[1]: Stopped target User and Group Name Lookups.
Mai 28 03:03:45 nixos-ups-cluster systemd[1]: Stopping User and Group Name Lookups...
Mai 28 03:03:45 nixos-ups-cluster systemd[1]: Stopping Name Service Cache Daemon (nsncd)...
Mai 28 03:03:45 nixos-ups-cluster systemd[1]: nscd.service: Deactivated successfully.
Mai 28 03:03:45 nixos-ups-cluster systemd[1]: Stopped Name Service Cache Daemon (nsncd).
Mai 28 03:03:45 nixos-ups-cluster systemd[1]: Starting Name Service Cache Daemon (nsncd)...
Mai 28 03:03:45 nixos-ups-cluster systemd[1]: Finished Extra networking commands..
Mai 28 03:03:45 nixos-ups-cluster systemd[1]: Reached target Network.
Mai 28 03:03:45 nixos-ups-cluster systemd[1]: Starting SSH Daemon...
Mai 28 03:03:45 nixos-ups-cluster systemd[1]: Starting Uninterruptible Power Supplies (Daemon)...
Mai 28 03:03:45 nixos-ups-cluster nsncd[1131]: May 28 01:03:45.367 INFO started, config: Config { ignored_request_types: {}, worker_count: 8, handoff_timeout: 10s }, path: "/var/run/nscd/socket"
Mai 28 03:03:45 nixos-ups-cluster systemd[1]: Started Name Service Cache Daemon (nsncd).
Mai 28 03:03:45 nixos-ups-cluster systemd[1]: Reached target Host and Network Name Lookups.
Mai 28 03:03:45 nixos-ups-cluster systemd[1]: Reached target User and Group Name Lookups.
Mai 28 03:03:45 nixos-ups-cluster systemd[1]: Starting Permit User Sessions...
Mai 28 03:03:45 nixos-ups-cluster systemd[1]: Finished Permit User Sessions.
Mai 28 03:03:45 nixos-ups-cluster systemd[1]: Started Getty on tty1.
Mai 28 03:03:45 nixos-ups-cluster systemd[1]: Started Serial Getty on ttyS1.
Mai 28 03:03:45 nixos-ups-cluster systemd[1]: Reached target Login Prompts.
Mai 28 03:03:45 nixos-ups-cluster sshd[1136]: Server listening on 0.0.0.0 port 22.
Mai 28 03:03:45 nixos-ups-cluster sshd[1136]: Server listening on :: port 22.
Mai 28 03:03:45 nixos-ups-cluster systemd[1]: Started SSH Daemon.
Mai 28 03:03:46 nixos-ups-cluster upsd[1156]: Network UPS Tools upsd 2.8.4 release
Mai 28 03:03:46 nixos-ups-cluster upsd[1156]: WARNING: /etc/nut/upsd.conf is world readable (hope you don't have passwords there)
Mai 28 03:03:46 nixos-ups-cluster upsd[1156]: WARNING: /etc/nut/upsd.conf is world readable (hope you don't have passwords there)
Mai 28 03:03:46 nixos-ups-cluster upsd[1156]: not listening on 192.168.198.180 port 3493
Mai 28 03:03:46 nixos-ups-cluster upsd[1156]: not listening on 192.168.198.180 port 3493
Mai 28 03:03:46 nixos-ups-cluster upsd[1156]: no listening interface available
Mai 28 03:03:46 nixos-ups-cluster upsd[1156]: no listening interface available
Mai 28 03:03:46 nixos-ups-cluster systemd[1]: upsd.service: Control process exited, code=exited, status=1/FAILURE
Mai 28 03:03:46 nixos-ups-cluster systemd[1]: upsd.service: Failed with result 'exit-code'.
Mai 28 03:03:46 nixos-ups-cluster systemd[1]: Failed to start Uninterruptible Power Supplies (Daemon).
Mai 28 03:03:46 nixos-ups-cluster systemd[1]: upsd.service: Consumed 515ms CPU time over 1.047s wall clock time, 15.3M memory peak, 9.2M read from disk.
Mai 28 03:03:46 nixos-ups-cluster systemd[1]: Starting Uninterruptible Power Supplies (Register all UPS)...
Mai 28 03:03:46 nixos-ups-cluster upsdrvctl[1158]: Network UPS Tools upsdrvctl - UPS driver controller 2.8.4 release
Mai 28 03:03:46 nixos-ups-cluster upsdrvctl[1159]: Network UPS Tools 2.8.4 release - Generic HID driver 0.67
Mai 28 03:03:46 nixos-ups-cluster upsdrvctl[1159]: USB communication driver (libusb 1.0) 0.50
Mai 28 03:03:46 nixos-ups-cluster upsdrvctl[1159]: libusb1: Could not open any HID devices: no USB buses (or devices) found
Mai 28 03:03:46 nixos-ups-cluster upsdrvctl[1159]: No matching HID UPS found
Mai 28 03:03:46 nixos-ups-cluster upsdrvctl[1159]: upsnotify: notify about state NOTIFY_STATE_STOPPING with libsystemd: was requested, but not running as a service unit now, will not spam more about it
Mai 28 03:03:46 nixos-ups-cluster upsdrvctl[1158]: Driver failed to start (exit status=1)
Mai 28 03:03:46 nixos-ups-cluster upsdrvctl[1158]: WARNING: /nix/store/l2h0gs0k8g2jn4yjch94pm7k26c6hlpv-nut-2.8.4/bin/upsdrvctl was called directly on a system with systemd support.
Mai 28 03:03:46 nixos-ups-cluster upsdrvctl[1158]:     Please consider using 'upsdrvsvcctl' instead, to avoid conflicts with
Mai 28 03:03:46 nixos-ups-cluster upsdrvctl[1158]:     nut-driver service instances prepared by 'nut-driver-enumerator'!
Mai 28 03:03:46 nixos-ups-cluster systemd[1]: upsdrv.service: Main process exited, code=exited, status=1/FAILURE
Mai 28 03:03:46 nixos-ups-cluster systemd[1]: upsdrv.service: Failed with result 'exit-code'.
Mai 28 03:03:46 nixos-ups-cluster systemd[1]: Failed to start Uninterruptible Power Supplies (Register all UPS).
Mai 28 03:03:46 nixos-ups-cluster systemd[1]: upsdrv.service: Consumed 80ms CPU time over 161ms wall clock time, 2.7M memory peak, 1.6M read from disk.
Mai 28 03:03:46 nixos-ups-cluster systemd[1]: Reached target Multi-User System.
Mai 28 03:03:46 nixos-ups-cluster systemd[1]: Startup finished in 2.101s (kernel) + 15.007s (initrd) + 10.348s (userspace) = 27.457s.

Additional context

I am not sure about the warning to please consider using upsdrvsvcctl instead. Maybe it is related?

System metadata

~ $ nix-shell -p nix-info --run "nix-info -m"

  • system: "aarch64-linux"
  • host os: Linux 6.18.33, NixOS, 26.05 (Yarara), 26.05.20260524.705e992
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.34.7
  • channels(root): "nixos-25.05.806304.dfcd5b901dba"
  • nixpkgs: /nix/store/nmcl84605abyizaviws06rwzcvkgpn52-source

Notify maintainers

@nbp


Note for maintainers: Please tag this issue in your pull request description. (i.e. Resolves #ISSUE.)

I assert that this issue is relevant for Nixpkgs

Is this issue important to you?

Add a :+1: reaction to issues you find important.

kwinz avatar May 28 '26 12:05 kwinz

Those systemd overrides in my flake.nix seem to fix or at least work around the problem. But I would rather it get fixed upstream in NixOS directly:

  # to prevent usb/network races
  systemd.services.upsdrv = {
    after = pkgs.lib.mkForce [
      "systemd-udev-settle.service"
      "local-fs.target"
    ];

    wants = [
      "systemd-udev-settle.service"
    ];

    serviceConfig = {
      Restart = "on-failure";
      RestartSec = "10s";
      StartLimitIntervalSec = "2min";
      StartLimitBurst = 20;
    };
  };

  systemd.services.upsd = {
    after = pkgs.lib.mkForce [
      "network-online.target"
      "upsdrv.service"
    ];

    wants = [
      "network-online.target"
      "upsdrv.service"
    ];

    # Do not require upsdrv hard, or one early USB failure
    # can permanently fail upsd during boot.
    requires = pkgs.lib.mkForce [ ];

    serviceConfig = {
      Restart = "on-failure";
      RestartSec = "10s";
      StartLimitIntervalSec = "2min";
      StartLimitBurst = 20;
    };
  };

  systemd.services.upsmon = {
    after = pkgs.lib.mkForce [
      "upsd.service"
    ];

    wants = [
      "upsd.service"
    ];

    serviceConfig = {
      Restart = "on-failure";
      RestartSec = "10s";
      StartLimitIntervalSec = "2min";
      StartLimitBurst = 20;
    };
  };

kwinz avatar May 28 '26 12:05 kwinz

This happened to me on one of my machines using 25.11, I haven't tried to update yet. The fix was to add this:

systemd.services.upsdrv = {
  after = [ "systemd-udev-settle.service" ];
  wants = [ "systemd-udev-settle.service" ];
};

xoconoch avatar May 30 '26 17:05 xoconoch