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