![Forrest logo](/images/logo.png)
nix-store:tldr:0d198
The nix-store --optimise
command is used in Nix, a purely functional package manager, to optimize the Nix store. The Nix store is a directory where all the packages and dependencies are stored on the system.
When you install packages using Nix, it creates a new store path for each package and its dependencies. Over time, unused or old versions of packages can accumulate in the Nix store, taking up disk space.
The --optimise
option of the nix-store
command helps to clean up and reduce the size of the Nix store by removing redundant and unused paths. It performs several operations to optimize the Nix store:
-
Garbage collection: It removes unused store paths that are no longer referenced by any installed packages or derivations. This helps to reclaim disk space by deleting packages that are no longer needed.
-
Compression: It compresses store paths using various compression algorithms like brotli or gzip, which reduces the overall disk usage. This compression is done transparently, so it doesn't affect package accessibility.
-
Substitutes pruning: Nix has a feature called "substitutes" that allows downloading pre-built binaries instead of building packages from source. The
--optimise
option removes any outdated or unused substitutes from the substitute store.
It's important to run nix-store --optimise
periodically to keep the Nix store optimized and prevent it from accumulating unnecessary packages, saving disk space and potentially improving performance.