1 # Cleaning the Nix Store {#sec-nix-gc}
3 Nix has a purely functional model, meaning that packages are never
4 upgraded in place. Instead new versions of packages end up in a
5 different location in the Nix store (`/nix/store`). You should
6 periodically run Nix's *garbage collector* to remove old, unreferenced
7 packages. This is easy:
13 Alternatively, you can use a systemd unit that does the same in the
17 # systemctl start nix-gc.service
20 You can tell NixOS in `configuration.nix` to run this unit automatically
21 at certain points in time, for instance, every night at 03:15:
25 nix.gc.automatic = true;
26 nix.gc.dates = "03:15";
30 The commands above do not remove garbage collector roots, such as old
31 system configurations. Thus they do not remove the ability to roll back
32 to previous configurations. The following command deletes old roots,
33 removing the ability to roll back to them:
36 $ nix-collect-garbage -d
39 You can also do this for specific profiles, e.g.
42 $ nix-env -p /nix/var/nix/profiles/per-user/eelco/profile --delete-generations old
45 Note that NixOS system configurations are stored in the profile
46 `/nix/var/nix/profiles/system`.
48 Another way to reclaim disk space (often as much as 40% of the size of
49 the Nix store) is to run Nix's store optimiser, which seeks out
50 identical files in the store and replaces them with hard links to a
54 $ nix-store --optimise
57 Since this command needs to read the entire Nix store, it can take quite
60 ## NixOS Boot Entries {#sect-nixos-gc-boot-entries}
62 If your `/boot` partition runs out of space, after clearing old profiles
63 you must rebuild your system with `nixos-rebuild boot` or `nixos-rebuild
64 switch` to update the `/boot` partition and clear space.