![Forrest logo](/images/logo.png)
nix3-store:tldr:478a3
The command "nix store optimise" is used in the Nix package manager to optimize the storage occupied by the Nix store.
The Nix store is a directory that holds all the installed packages and their dependencies. Over time, as packages are installed, updated, or removed, the Nix store can accumulate unused or redundant files. This can take up unnecessary disk space.
The "nix store optimise" command helps to reclaim disk space by removing duplicates and old versions of packages that are no longer needed. It performs several operations to optimize the store efficiently:
-
Garbage collection: It identifies and removes packages that are no longer referenced by any active profiles or packages. These could be old versions of packages, or packages that were uninstalled but still present in the store.
-
Store deduplication: It identifies duplicate files in the store and replaces them with hard links. Since Nix uses content-addressable storage, identical files can be safely replaced with links without affecting the correctness of the system.
-
Dead symlink removal: It removes orphaned symbolic links in the store. These are symlinks that don't point to any existing files.
The "nix store optimise" command helps keep the Nix store clean and efficient, reducing disk usage and improving system performance. It is typically run periodically, either manually or as part of a scheduled maintenance task.