๐งน Maintenance & Cleanup โ
Over time, your NixOS system will accumulate old configurations and packages. By default, the workstation takes care of itself by running a weekly automatic garbage collection that deletes data older than 14 days.
If you ever need to manually free up disk space or inspect your system's history, use the commands below.
๐ Inspecting Your System โ
Before deleting anything, you might want to see what is currently keeping files pinned in the system.
To see all active "roots" (configurations that tell Nix not to delete a package):
nix-store --gc --print-rootsTo view a detailed history of your system generations (the entries you see in the GRUB boot menu):
nix profile history --profile /nix/var/nix/profiles/system๐๏ธ Manual Cleanup โ
If you are running low on disk space, you can manually trigger the garbage collector.
Best Practice: Always keep recent generations around just in case you need to roll back. The following command safely deletes data older than 14 days:
doas nix-collect-garbage --delete-older-than 14d(Note: Avoid deleting generations too aggressively! If you just made major changes to graphics or networking, keep at least one known-good generation until you are sure the new one is completely stable).