π§Ή 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π Inspecting Store Usage β
If the automatic cleanup above still leaves /nix/store larger than expected, it helps to see what is retaining the space before deleting anything. just top ranks real store paths by their actual size:
just topTwo common causes of a bloated store to look out for in the results:
- Duplicated toolchains from mixing nixpkgs channels. If any packages are pinned to
nixpkgs-unstablewhile the rest of the system uses the stable channel, you'll often see two separate copies ofglibc/gccand their dependents β nothing is shared between the two channels' closures. - Retained build-time dependencies.
nix.settings.keep-outputsandkeep-derivations(seedocs/dev/architecture/tuning.md) intentionally keep build dependencies around for faster rebuilds, at the cost of store size.
Before reaching for just gc, try just optimise first β it hard-links identical files across store paths and can reclaim space with no risk of losing anything.
ποΈ 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).