Nix-daemon.{socket,service} not recognized on boot (Nix overlay on Gentoo)

Got some help from people elsewhere. There isn’t any built-in way to tell systemd that it needs to mount a particular partition before it can read one of its unit files, but you can kludge it with a “path” unit. Save this file as /etc/systemd/system/nix-daemon-units.path

[Unit]
Description=Watch for linked Nix unit files

[Install]
WantedBy=sockets.target

[Path]
DirectoryNotEmpty=/nix/var/nix/profiles/default/lib/systemd/system

and this file as /etc/systemd/system/nix-daemon-units.service

[Unit]
Description=Reload systemd unit configuration when Nix units become available

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/systemctl daemon-reload
ExecStart=/usr/bin/systemctl start nix-daemon.socket

and then do systemctl enable nix-daemon-units.path; reboot as root. The .path file makes systemd watch for files to appear in the directory where nix-daemon.{service,socket} actually live. When they do, it triggers the matching .service file, which reloads the service configuration (picking up the newly available unit files) and activates the listening socket for the Nix daemon. You need both the ExecStart lines, because daemon-reload alone doesn’t re-trigger units that are enabled but failed earlier.

1 Like