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:
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?
I encountered this error trying to have a separate /nix partition on a Non-NixOS system. I didn’t find a nice way to fix it, but as a workaround I created a service that gets it started. This is the only mention of the issue I found, so I’m posting here in case anyone else finds it.
/etc/systemd/system/nix-kludge.service:
[Unit]
Description=Fix nix-daemon for separate /nix partition
RequiresMountsFor=/nix
[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl daemon-reload
ExecStart=/usr/bin/systemctl start nix-daemon.socket
[Install]
WantedBy=multi-user.target
@samh That shouldn’t be necessary. The nix-daemon.socket unit should already have the equivalent of RequiresMountsFor=/nix/var/nix/daemon-socket/socket thanks to the default dependencies of socket units, and the nix-daemon.service unit that nix ships with already has:
@ElvishJerricco You are right that it has something like that. As far as I can tell, the problem is that the socket and service files are symbolic links:
Ah, right, I had forgotten the context of this thread Indeed that would be an issue. You could work around that by mounting /nix in your initramfs. How to do that depends on your distro, but on distros with systemd-in-initrd (e.g. fedora) you should be able to just add x-initrd.mount to the entry in /etc/fstab in your root fs, and the initrd will pick it up after mounting the root fs and before switching to the main system.
After some more searching I had found this blog post: Metamagical
It describes another way to fix it on Fedora (and derivatives), involving an /etc/fstab.sys file. I would have been satisfied with that, but the x-initrd.mount solution is simpler (and better documented compared to dracut and /etc/fstab.sys).