How to add a rescue option to bootloader

There has been time when I had to boot into a NixOS install image to fix issues with my system, for example when ZFS didn’t export correctly and won’t import. The usually way is to get a USB drive with NixOS install image and boot from that, but sometimes I might not have one available. I was wondering if one could add an option to bootloader with NixOS install ISO.

I looked at Grub options and the only thing that kinda fits is boot.loader.grub.extraEntries, but it assumes such an image is already available somewhere. If I wanted to make sure the NixOS ISO is always available on the /boot partition that is ensured by my NixOS system itself when I run nixos-rebuild, how would I go about doing that? Is that even doable?

Any pointers would be appreciated. If this is doable I’d be happy to work on implementing it and submitting a PR so there’s an easy way to do this with an option like boot.loader.grub.nixosRescueEntry = true; or similar.

I’ve found a config implementing your approach in a similar way: https://github.com/cleverca22/nixos-configs/blob/0055f11b62b3278adebdfa115386e0ccf3d350f8/rescue_boot.nix

1 Like