Removing old generations can be sometimes tricky in NixOS. Here is a small summary on how I usually process those steps:
First I run the garbage collector to remove generations older than 30 days:
sudo nix-collect-garbage --delete-older-than 30d
This will remove old generations and free up some space on your disk. The result should look something like this:
61940 store paths deleted, 103421.63 MiB freed
This is fine for the store. But we need to clean the boot entries as well, since this partition is usually very small and can run out of space pretty quickly. To solve this, we can just run the rebuild command, which will take care of the entries:
sudo nixos-rebuild switch
This should do the trick to keep your disk space free of old generations and app versions.
Thank you for reading this far! Let’s connect. You can @ me on Twitter (@debilofant) with comments, or feel free to follow. Please like/share this article so that it reaches others as well.