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:
24 nix.gc.automatic = true;
25 nix.gc.dates = "03:15";
28 The commands above do not remove garbage collector roots, such as old
29 system configurations. Thus they do not remove the ability to roll back
30 to previous configurations. The following command deletes old roots,
31 removing the ability to roll back to them:
34 $ nix-collect-garbage -d
37 You can also do this for specific profiles, e.g.
40 $ nix-env -p /nix/var/nix/profiles/per-user/eelco/profile --delete-generations old
43 Note that NixOS system configurations are stored in the profile
44 `/nix/var/nix/profiles/system`.
46 Another way to reclaim disk space (often as much as 40% of the size of
47 the Nix store) is to run Nix's store optimiser, which seeks out
48 identical files in the store and replaces them with hard links to a
52 $ nix-store --optimise
55 Since this command needs to read the entire Nix store, it can take quite
58 ## NixOS Boot Entries {#sect-nixos-gc-boot-entries}
60 If your `/boot` partition runs out of space, after clearing old profiles
61 you must rebuild your system with `nixos-rebuild boot` or `nixos-rebuild
62 switch` to update the `/boot` partition and clear space.