Cleaning the nix store: Difference between revisions

From NixOS Wiki
imported>Makefu
add more references and a command to find result files
Jalil (talk | contribs)
m Remove unnecessary leading white space from command
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
Sometimes your store fills up the disk, but a simple <syntaxHighlight>nix-store --gc</syntaxHighlight> does not seem to clean all that much.
Sometimes your store fills up the disk, but a simple
<syntaxhighlight lang=text>nix-store --gc</syntaxhighlight>
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.
This usually means that you have some old collection roots that keep old versions of nixpkgs around.


Sometimes <code>result</code> files created by an ad-hoc <code>nix-build</code> bind a lot of resources, these can be found by running:
Sometimes <code>result</code> files created by an ad-hoc <code>nix-build</code> bind a lot of resources, these can be found by running:
<syntaxHighlight>
 
<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)"
</syntaxHighlight>
</syntaxhighlight>


Additional Resources about cleaning up the nix-store are:
Additional Resources about cleaning up the ''nix-store'':


* https://matthewrhone.dev/nixos-package-guide#cleanup-old-packages-user-wide
* https://matthewrhone.dev/nixos-package-guide#cleanup-old-packages-user-wide
* https://nixos.wiki/wiki/Storage_optimization
* [[Storage optimization]]
* https://old.reddit.com/r/NixOS/comments/8m1n3d/taking_out_the_trash/
* https://old.reddit.com/r/NixOS/comments/8m1n3d/taking_out_the_trash/


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


* https://github.com/symphorien/nix-du
* https://github.com/symphorien/nix-du
Line 20: Line 23:
* https://github.com/cdepillabout/nix-query-tree-viewer
* https://github.com/cdepillabout/nix-query-tree-viewer
* https://github.com/craigmbooth/nix-visualize
* https://github.com/craigmbooth/nix-visualize
[[Category:nix]]

Latest revision as of 07:22, 7 October 2024

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)"

Additional Resources about cleaning up the nix-store:

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