Hello. I was refactoring parts of my Nix config and rebuilded. Went to sleep and woke up next day, booted my PC and encountered, what to me seems like, a broken or corrupted GRUB.
Hi and thank you for replying. Your suggestion did work, although I might have done it a bit differently than what I’m guessing you intended.
I didn’t reinstall NixOS, as I didn’t want to wipe my root partition, so I used this post as guidance.
Anyway here’s what worked for me:
Boot a live NixOS USB and mount root and boot partitions: sudo mount /dev/sda5 /mnt sudo mount /dev/sda1 /mnt/boot
Back up old bootloader (or alternatively delete it, if you are missing space): sudo mv /boot/EFI/nixos /boot/EFI/nixos.bak
Enter: sudo nixos-enter unset SUDO_USER
Disable logrotate in /etc/nixos/configuration.nix by adding: services.logrotate.enable = false;
Rebuild and install new bootloader: nixos-rebuild boot -I nixos-config=/etc/nixos/configuration.nix --install-bootloader
Reboot and you should be able to enter the bootloader normally like me. Make sure to now delete /boot/EFI/nixos.bak so that your /boot has space for rebuilding.
I didn’t reinstall NixOS, as I didn’t want to wipe my root partition
You don’t have to wipe the root partition for that. The nixos-install command is idempotent: you can re-run it as much as you want and it will just make sure the system is in a consistent state.
So, in your case it would only rebuild the bootloader files, since you deleted them.
Sidenote, if your kernels were at /boot/EFI/nixos, I’m pretty sure that’s systemd-boot, not grub. I believe NixOS’s grub module installs kernels in /boot/kernels or something like that. This is a good thing; NixOS maintainers generally recommend systemd-boot over grub. Just something worth noting. Also, you didn’t actually delete the systemd-boot loader, so I’m guessing --install-bootloader (which triggers bootctl install instead of bootctl update) probably just always overwrites it.