Forrest logo
back to the nix tool

nix3-store:tldr:478a3

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

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:

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

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

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

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 tool