At least with UEFI/_gummiboot_ calling nix-collect-garbage -d doesn't delete the old boot entries. Does it work with GRUB?
It deletes entries with grub for me, yes.
I believe old boot menu entries -- i.e. entries for which there no longer is an active profile -- are discarded by nixos-rebuild.
@peti You are right, calling nixos-rebuild clean up old boot entries. Hm, maybe nix-collect-garbage -d should also run nixos-rebuild boot ?
Problem is that nix-collect-garbage is a Nix tool so it knows nothing about NixOS.
I think in this case we can close this issue. Manually calling nixos-rebuild cleans up old boot entries for GRUB / gummiboot. This should be good enough
I have run into the same problem and just calling nixos-rebuild doesn't seem to work, as it appears to create a new build, and since the current build has not been purged it keeps the entry, thereby always leaving you with a minimum of two generations.
How about a nixos-rebuild remove-old-entries command ?
I find the current UX a bit clunky; as you need to remember to run nix-collect-garbage as root (to get the system profile) and then also run nixos-rebuild afterwards which I forget often.
While this may have worked for older versions, it doesn't work for the current 19.09 version, which is all I have experience with. Collecting the garbage and rebuilding only adds yet another entry to the boot menu. The ONLY way I have of removing the boot entries is by doing a fresh install.
Did you run collect-garbage as root? You need to clear the system profile; not your user profile.
sudo, so yes. After some further testing, including a completely fresh install, it seems to be that only manually-named (-p) entries are left after a garbage collection & rebuild.
So how does one delete manually-named entries?
Well, I found a way:
sudo nix-store --delete --ignore-liveness /nix/store/<entry>
sudo rm /boot/loader/entries/<entry>
Slight problem. While that works, it comes with a price. You'll never be able to do another rebuild. DO NOT DO THAT!!!!
Got it! FINALLY! Here goes:
sudo rm /nix/var/nix/profiles/system-profiles/<entries> (There will be two for each)
sudo nix-collect-garbage -d
sudo nixos-rebuild switch
sudo rm /boot/loader/entries/<entry>
shutdown -r now
Voila!
@fourdragons @jgeerds To remove all but the most recent grub boot entry run: sudo nix-env --delete-generations old --profile /nix/var/nix/profiles/system followed by sudo /nix/var/nix/profiles/system/bin/switch-to-configuration switch.
You do not need to use nixos-rebuild or manually remove grub boot entries. Nixos updates the grub boot entry when running switch-to-configuration switch or switch-to-configuration boot to only the live profiles. So, if you first run sudo nix-env --delete-generations old --profile /nix/var/nix/profiles/system to remove all but the newest system garbage collection roots followed by sudo /nix/var/nix/profiles/system/bin/switch-to-configuration switch which reloads the system configuration you are already on, your grub.cfg will only have one entry in it and you have not had to change your system configuration or reboot the box. If you want to then garbage collect the old profiles you can run nix-store --gc.
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/how-to-remove-grub-entries-in-grub-cfg/9059/3
Most helpful comment
I have run into the same problem and just calling
nixos-rebuilddoesn't seem to work, as it appears to create a new build, and since the current build has not been purged it keeps the entry, thereby always leaving you with a minimum of two generations.