Nix Cookbook: Difference between revisions

Mth (talk | contribs)
mNo edit summary
Mth (talk | contribs)
No edit summary
Line 7: Line 7:
==== Remove old generations ====
==== Remove old generations ====


When you make changes to your system, Nix creates a new system [[generation]]. All of the changes to the system since the previous generation are stored there. Old generations can add up and will not be removed automatically by default. You can see your generations with:
When you make changes to your system, Nix creates a new system [[generation]]. All of the changes to the system since the previous generation are stored there. Old generations can add up and will not be removed automatically by default. You can see your saved system generations with:


<syntaxHighlight lang=shell>
<syntaxhighlight lang="shell-session">
   $ nix-env --list-generations
   # nix-env --profile /nix/var/nix/profiles/system --list-generations
</syntaxHighlight>
</syntaxhighlight>


To keep just your current generation and the two older than it:
To keep just your current generation and the two older than it:


<syntaxHighlight lang=shell>
<syntaxhighlight lang="shell-session">
   $ nix-env --delete-generations +3
   # nix-env --profile … --delete-generations +3
</syntaxHighlight>
</syntaxhighlight>


To remove all but your current generation:
To remove all but your current generation:


<syntaxHighlight lang=shell>
<syntaxhighlight lang="shell-session">
   $ nix-env --delete-generations old
   # nix-env --profile … --delete-generations old
</syntaxHighlight>
</syntaxhighlight>Apart from the system profile in <code>/nix/var/nix/profiles/system</code>, every user has profiles for their user environment and channels. The operations above may be repeated for those profiles. By default, they are located at <code>~/.nix-profile</code> and <code>~/.nix-defexpr/channels</code>. For more information on profile locations, see [https://nix.dev/manual/nix/stable/command-ref/nix-env#files Nix Manual - nix-env - Files].


===== Generation trimmer script =====
===== Generation trimmer script =====