2014-08-24 19:18:18 +02:00
|
|
|
|
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
|
|
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
|
|
|
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
|
|
|
version="5.0"
|
|
|
|
|
xml:id="sec-nix-gc">
|
2018-05-02 01:57:09 +02:00
|
|
|
|
<title>Cleaning the Nix Store</title>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Nix has a purely functional model, meaning that packages are never upgraded
|
|
|
|
|
in place. Instead new versions of packages end up in a different location in
|
|
|
|
|
the Nix store (<filename>/nix/store</filename>). You should periodically run
|
|
|
|
|
Nix’s <emphasis>garbage collector</emphasis> to remove old, unreferenced
|
|
|
|
|
packages. This is easy:
|
2014-08-24 19:18:18 +02:00
|
|
|
|
<screen>
|
2019-06-17 13:25:50 +02:00
|
|
|
|
<prompt>$ </prompt>nix-collect-garbage
|
2014-08-24 19:18:18 +02:00
|
|
|
|
</screen>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Alternatively, you can use a systemd unit that does the same in the
|
|
|
|
|
background:
|
2014-08-24 19:18:18 +02:00
|
|
|
|
<screen>
|
2019-06-17 13:25:50 +02:00
|
|
|
|
<prompt># </prompt>systemctl start nix-gc.service
|
2014-08-24 19:18:18 +02:00
|
|
|
|
</screen>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
You can tell NixOS in <filename>configuration.nix</filename> to run this unit
|
|
|
|
|
automatically at certain points in time, for instance, every night at 03:15:
|
2014-08-24 19:18:18 +02:00
|
|
|
|
<programlisting>
|
2018-04-05 10:43:56 +02:00
|
|
|
|
<xref linkend="opt-nix.gc.automatic"/> = true;
|
|
|
|
|
<xref linkend="opt-nix.gc.dates"/> = "03:15";
|
2014-08-24 19:18:18 +02:00
|
|
|
|
</programlisting>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
The commands above do not remove garbage collector roots, such as old system
|
|
|
|
|
configurations. Thus they do not remove the ability to roll back to previous
|
|
|
|
|
configurations. The following command deletes old roots, removing the ability
|
|
|
|
|
to roll back to them:
|
2014-08-24 19:18:18 +02:00
|
|
|
|
<screen>
|
2019-06-17 13:25:50 +02:00
|
|
|
|
<prompt>$ </prompt>nix-collect-garbage -d
|
2014-08-24 19:18:18 +02:00
|
|
|
|
</screen>
|
2018-05-02 01:57:09 +02:00
|
|
|
|
You can also do this for specific profiles, e.g.
|
2014-08-24 19:18:18 +02:00
|
|
|
|
<screen>
|
2019-06-17 13:25:50 +02:00
|
|
|
|
<prompt>$ </prompt>nix-env -p /nix/var/nix/profiles/per-user/eelco/profile --delete-generations old
|
2014-08-24 19:18:18 +02:00
|
|
|
|
</screen>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Note that NixOS system configurations are stored in the profile
|
|
|
|
|
<filename>/nix/var/nix/profiles/system</filename>.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Another way to reclaim disk space (often as much as 40% of the size of the
|
|
|
|
|
Nix store) is to run Nix’s store optimiser, which seeks out identical files
|
|
|
|
|
in the store and replaces them with hard links to a single copy.
|
2014-08-24 19:18:18 +02:00
|
|
|
|
<screen>
|
2019-06-17 13:25:50 +02:00
|
|
|
|
<prompt>$ </prompt>nix-store --optimise
|
2014-08-24 19:18:18 +02:00
|
|
|
|
</screen>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
Since this command needs to read the entire Nix store, it can take quite a
|
|
|
|
|
while to finish.
|
2018-05-02 01:57:09 +02:00
|
|
|
|
</para>
|
2018-09-01 03:37:07 +02:00
|
|
|
|
<section xml:id="sect-nixos-gc-boot-entries">
|
|
|
|
|
<title>NixOS Boot Entries</title>
|
|
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 19:17:30 +02:00
|
|
|
|
If your <filename>/boot</filename> partition runs out of space, after
|
|
|
|
|
clearing old profiles you must rebuild your system with
|
|
|
|
|
<literal>nixos-rebuild</literal> to update the <filename>/boot</filename>
|
|
|
|
|
partition and clear space.
|
2018-09-01 03:37:07 +02:00
|
|
|
|
</para>
|
|
|
|
|
</section>
|
2016-06-01 16:23:32 +02:00
|
|
|
|
</chapter>
|