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:
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
$ systemctl --user --type=target
UNIT LOAD ACTIVE SUB DESCRIPTION
basic.target loaded active active Basic System
default.target loaded active active Main User Target
graphical-session-pre.target loaded active active Session services which should run early before the graphical session is brought up
graphical-session.target loaded active active Current graphical user session
hm-graphical-session.target loaded active active Home Manager X session
paths.target loaded active active Paths
sockets.target loaded active active Sockets
timers.target loaded active active Timers
tray.target 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?
Ah, rebooting with default.target 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.
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 :-/