According to the documentation, to remove old generations of NixOS, all that’s needed is to run this command:
$ nix-collect-garbage -d
I believe it removes the generations and their symlinks from NixOS, effectively rendering any rollbacks impossible, from what’s displayed on the console output. What it does NOT do is remove these generations from the EFI menu. To do this you must run these commands along with the garbage collector.
Is there any reason why this is the case? If the old generations are incapable of booting up, why keep them in the EFI menu?
It does, it just removes it from the nix store. The
nix-collect-garbage command is unaware of boot entry logic.
Or you can do
nixos-rebuild switch or
nixos-rebuild boot. There’s some logic that it should clean up stale generations.
Separation of concerns. Many of the
nix commands, just assume nix behavior. They don’t try to interact with your system at large, after all, nix can be used on more things than just NixOS. The
nixos commands do effectual things, and may modify your system.
However, it probably would be nice for
nixos-rebuild to have a “prune-stale-boot-entries” command, as the
switch | boot will also install a new boot entry.
The separation of concerns makes sense. I’ve ran
nixos-rebuild switch and
boot after calling
nix-collect-garbage with no success though. It’s how I ended up with 59 generations before I decided to look for solutions outside of what was prescribed in the documentation.
Collect garbage and then run
/run/current-system/bin/switch-to-configuration boot - that should clear it up.
just to make sure, you’re running
sudo nix-collect-garbage -d right?
switch-to-configuration command worked! I’ll run this from now on.
Wow I’m so glad you mentioned this. I have been watching entries accumulate and wondering why
nix-collect-garbage -d wasn’t getting rid of them. I wasn’t running it as sudo Thanks for stating the obvious, it really helped me out!