Forrest logo
back to the nix-store tool

nix-store:tldr:0d198

nix-store: Hard-link identical files together to reduce space usage.
$ nix-store --optimise
try on your machine

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:

  1. 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.

  2. 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.

  3. 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.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the nix-store tool