Add NixOS to current systemd bootloader

I’m in the process of reinstalling my virtual machines as bare-metal installs, using EndeavourOS as the initial distro with systemd-boot. I’ve added Debian, Fedora, and openSUSE to the existing bootloader, but I’ll be damned if I can find any documentation that describes how to add NixOS. While there are some tutorials on installing NixOS last w/systemd-boot then letting it control everything exist, that’s not an option for me.

So far, the closest I’ve gotten is installing NixOS with GRUB, then chainloading via systemd-boot. But that’s not working (can’t find the NixOS root partition, don’t really want this setup anyways). Since I can’t find kernel-install, that option is also out.

If anyone can show me how the systemd-boot configuration entries are created, I’d much appreciate it.

Why not? It’s easy enough to configure systemd-boot with NixOS. And NixOS really wants to be able to create its own boot entries in order to offer its hallmark feature of putting generations in the boot menu.

Unfortunately NixOS doesn’t really have a way of populating boot entries without controlling the boot loader. I think it would be a pretty simple change to our systemd-boot module to support only managing NixOS’s systemd-boot style entries and files without actually managing systemd-bootx64.efi / BOOTX64.EFI itself.

1 Like

Yeah, I see what you mean. The systemd version in NixOS is very new, so that would not be an issue for my Arch-based systems. In this use-case, I would prefer that Nix take over handling the bootloader 100%.

I have used Nixos in the configuration you describe in the past. For me, it just worked, there was no need to do anything special.

You can can disable the hook in EOS that updates systemd-boot.

That being said, I don’t think it will matter all that much. Letting all the distros overwrite systemd-boot all the time probably won’t harm anything.

Especially since bootctl (the tool used to install / update systemd-boot on the ESP) checks the version number of the systemd-boot that’s already present to make sure it’s not doing a downgrade.

1 Like

OK, I’ve got my Nix system up and running - thanks a bunch! The only setting I couldn’t find was how to set the default loader to @saved. No biggie …

Will just deleting the file /usr/share/libalpm/hooks/systemd-boot.hook be enough? I guess I can chattr it, but will that affect future updates?

Don’t delete it, it will just be recreated on update. Instead override it. Something like sudo ln -s /dev/null /etc/pacman.d/hooks/systemd-boot.hook or just place a 0 byte file at that location.

1 Like