NixOS Delete Old Generations

by|inArticles||2 min read

Removing old generations on NixOS can be sometimes tricky. Here is a small summary on how I usually process those steps for nixos remove old generations:

First I run the garbage collector to remove old generations older than 30 days:

sudo nix-collect-garbage --delete-older-than 30d

This will remove old generations on nixos 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 of old generations of nixos as well. If you miss out to delete old nixos kernel entries in your boot partition you will run out of space on this partition since it is usually very small.  To delete old nixos kernel entries in the boot menu 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. I have chosen to garbage collect for generations older than 30 days. This value depends heavily on the frequency of your system upgrade cycle. If you update less frequent, you can increase this value to, let's say 60 days. On the other hand, if you update almost every day, you can choose 10 days to keep your system as compact as possible.

Thank you for reading this far! Let’s connect. You can @ me on X (@debilofant) with comments, or feel free to follow. Please like/share this article so that it reaches others as well.

Related Articles

© Copyright 2024 - - All rights reservedVer. 415