Jump to content

Cleaning the nix store: Difference between revisions

From NixOS Wiki
Jalil (talk | contribs)
m Remove unnecessary leading white space from command
Dwt (talk | contribs)
Add better Darwin command
 
Line 9: Line 9:
<syntaxhighlight lang="shell">
<syntaxhighlight lang="shell">
nix-store --gc --print-roots | egrep -v "^(/nix/var|/run/\w+-system|\{memory|/proc)"
nix-store --gc --print-roots | egrep -v "^(/nix/var|/run/\w+-system|\{memory|/proc)"
# Darwin
nix-store --gc --print-roots | egrep -v "^(/nix/var|/run/\w+-system|\{libproc)"
</syntaxhighlight>
</syntaxhighlight>



Latest revision as of 15:33, 8 March 2025

Sometimes your store fills up the disk, but a simple

nix-store --gc

does not seem to clean all that much.

This usually means that you have some old collection roots that keep old versions of nixpkgs around.

Sometimes result files created by an ad-hoc nix-build bind a lot of resources, these can be found by running:

nix-store --gc --print-roots | egrep -v "^(/nix/var|/run/\w+-system|\{memory|/proc)"
# Darwin
nix-store --gc --print-roots | egrep -v "^(/nix/var|/run/\w+-system|\{libproc)"

Additional Resources about cleaning up the nix-store:

There are multiple tools that can help with discovering gcroots and calculate the disk size: