at 18.09-beta 2.4 kB view raw
1<chapter xmlns="http://docbook.org/ns/docbook" 2 xmlns:xlink="http://www.w3.org/1999/xlink" 3 xmlns:xi="http://www.w3.org/2001/XInclude" 4 version="5.0" 5 xml:id="sec-nix-gc"> 6 <title>Cleaning the Nix Store</title> 7 <para> 8 Nix has a purely functional model, meaning that packages are never upgraded 9 in place. Instead new versions of packages end up in a different location in 10 the Nix store (<filename>/nix/store</filename>). You should periodically run 11 Nix’s <emphasis>garbage collector</emphasis> to remove old, unreferenced 12 packages. This is easy: 13<screen> 14$ nix-collect-garbage 15</screen> 16 Alternatively, you can use a systemd unit that does the same in the 17 background: 18<screen> 19# systemctl start nix-gc.service 20</screen> 21 You can tell NixOS in <filename>configuration.nix</filename> to run this unit 22 automatically at certain points in time, for instance, every night at 03:15: 23<programlisting> 24<xref linkend="opt-nix.gc.automatic"/> = true; 25<xref linkend="opt-nix.gc.dates"/> = "03:15"; 26</programlisting> 27 </para> 28 <para> 29 The commands above do not remove garbage collector roots, such as old system 30 configurations. Thus they do not remove the ability to roll back to previous 31 configurations. The following command deletes old roots, removing the ability 32 to roll back to them: 33<screen> 34$ nix-collect-garbage -d 35</screen> 36 You can also do this for specific profiles, e.g. 37<screen> 38$ nix-env -p /nix/var/nix/profiles/per-user/eelco/profile --delete-generations old 39</screen> 40 Note that NixOS system configurations are stored in the profile 41 <filename>/nix/var/nix/profiles/system</filename>. 42 </para> 43 <para> 44 Another way to reclaim disk space (often as much as 40% of the size of the 45 Nix store) is to run Nix’s store optimiser, which seeks out identical files 46 in the store and replaces them with hard links to a single copy. 47<screen> 48$ nix-store --optimise 49</screen> 50 Since this command needs to read the entire Nix store, it can take quite a 51 while to finish. 52 </para> 53 <section xml:id="sect-nixos-gc-boot-entries"> 54 <title>NixOS Boot Entries</title> 55 56 <para> 57 If your <filename>/boot</filename> partition runs out of space, after 58 clearing old profiles you must rebuild your system with 59 <literal>nixos-rebuild</literal> to update the <filename>/boot</filename> 60 partition and clear space. 61 </para> 62 </section> 63</chapter>