Nix-daemon doesn't start on boot on Ubuntu with multi-user installation and a bind-mounted /nix

Hi all,

I installed nix on a server running Ubuntu 20.04, with a separate /nix bind-mount. But nix-daemon doesn’t start on boot and I have to do the following manually on each reboot:

sudo systemctl daemon-reload
sudo systemctl start nix-daemon

The relavent bits in /etc/fstab is the following:

/dev/nvme0n1p5  /mnt/ssd        ext4     defaults                             0       2

# bind mount /nix
/mnt/ssd/nix    /nix            none     bind,x-systemd.requires=/mnt/ssd     0       0

I took a look at journalctl -b, but there’s no mentioning of nix-daemon at all, not even an error message.

One interesting thing is that I have to do systemctl daemon-reload on each reboot, otherwise systemd won’t recognize nix-daemon:

Unit nix-daemon.service could not be found.

Does this mean that the /nix partition was not visible to systemd during the early initialization s.t. the nix-daemon unit doesn’t get loaded at all?

If so, should I try to mount /mnt/data and nix partitions in initramfs? How?

I don’t know much about what nix installation does on non-nixos distros. But my best guess would be that some .service file is a symlink to some /nix/store path, and when systemd initializes during boot, this path doesn’t exist yet and therefore the symlink is dead and the service cannot be loaded.

You probably need to replace the service with another one that doesn’t reside in /nix/store. But then the question is if that will break during the next update or not.


Thanks for the suggestion. The nix-daemon.service and nix-daemon.sockets are indeed symlinked to /nix/store/<bla> and they probably are not available when systemd initializes.

But NixOS must be able to handle that somehow, given that /etc/systemd/system is a link to /etc/static/systemd/system which then links to /nix/store. How does NixOS handle this w/o problem?

It mounts /nix/store in initramfs, so it’s available before systemd even starts.

1 Like

I see. So I’ll just do the same for Ubuntu then.

@yipengsun It would be interesting to know if you have come to a solution for this.

Sorry, I didn’t pursue this further.