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 systemd.user.services.<service>
configuration property. Let’s look at this example:
systemd.user.services.tftp-network-boot = {
enable = true;
description = "TFTP Network Boot Server";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
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 systemd.services.tftp-network-boot
(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 192.168.44.100 /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.