NixOS 22.11: Systemd user services don't start automatically (but global ones do)

I’m facing the problem that my systemd user services don’t start automatically, unlike global services. I’m running a fresh NixOS 22.11 installation with GNOME as desktop environment.

Defining a systemd user service requires to use the<service> configuration property. Let’s look at this example: = {
      enable = true;
      description = "TFTP Network Boot Server";
      after = [ "" ];
      wantedBy = [ "" ];
      serviceConfig.ExecStart = "${pkgs.atftp}/sbin/atftpd --daemon --bind-address ${hostIp} ${tftpRoot}";
      # Ensure that the directory is created, if it doesn't exist.
      preStart = ''
        mkdir -m 0777 -p ${tftpRoot}

$ systemctl --user status tftp-network-boot shows:

○ tftp-network-boot.service - TFTP Network Boot Server
     Loaded: loaded (/etc/systemd/user/tftp-network-boot.service; enabled; preset: enabled)
     Active: inactive (dead)

This is the case after nixos rebuild switch as well as after a reboot.

If I switch the configuration to (removed user.),
$ sudo systemctl status tftp-network-boot shows:

○ tftp-network-boot.service - TFTP Network Boot Server
     Loaded: loaded (/etc/systemd/system/tftp-network-boot.service; enabled; preset: enabled)
     Active: inactive (dead) since Fri 2023-01-20 15:31:25 CET; 37ms ago
   Duration: 1ms
    Process: 37431 ExecStartPre=/nix/store/vrdnkmh0qfygi17yrl31ydxnng4h4vv4-unit-script-tftp-network-boot-pre-start/bin/tftp-network-boot-pre-start (code=exited, status=0/SUCCESS)
    Process: 37433 ExecStart=/nix/store/h4q25fqsc68qas4b1ypkmmymv45h3lyb-atftp-0.7.5/sbin/atftpd --daemon --bind-address /home/myuser/tftpboot (code=exited, status=0/SUCCESS)
   Main PID: 37433 (code=exited, status=0/SUCCESS)
         IP: 0B in, 0B out
        CPU: 4ms

Jan 20 15:31:25 nixos systemd[1]: Starting TFTP Network Boot Server...
Jan 20 15:31:25 nixos systemd[1]: Started TFTP Network Boot Serve

Surprisingly, I can’t find online documentation for starting user services automatically.

1 Like

There is no in the user systemd instance, so setting it to be wantedBy that doesn’t accomplish anything.

Also and are not working.

btw, systemctl --type=target lists the

Did you mean systemctl --user --type=target? If so, it’s probably because you implicitly created it by having a unit reference it. If not, you were listing the system instance :slight_smile:

$ systemctl --user --type=target
  UNIT                         LOAD   ACTIVE SUB    DESCRIPTION                                                                                 loaded active active Basic System               loaded active active Main User Target loaded active active Session services which should run early before the graphical session is brought up     loaded active active Current graphical user session  loaded active active Home Manager X session                 loaded active active Paths               loaded active active Sockets                loaded active active Timers                  loaded active active Home Manager System Tray

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.
9 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

Did you try a reboot (or at least a relog) again with any of these?

1 Like

Ah, rebooting with indeed does the trick. Thanks a lot! I didn’t know that I have to look at systemctl --user --type=target (with --user) to find suitable targets.


Glad I could help.

It seems nixos doesn’t automatically try to start any new or changed user services during activation, like it does for system services. Home-manager will start its own user services, but that leaves nixos’ user services without a helping hand from anywhere :-/


hi tejing NixOS wizard

What exactly do you mean by this? Do you mean that if it exists in Home-Manager nobody will fix this issue in NixOS?

I wasn’t being that indirect. I just meant that nothing currently starts them.