The Nix store

An on-disk storage system used by Nix to build, store, and cache packages and other artifacts

Concepts / The Nix store

The Nix store is a storage system in your filesystem with its root at /nix/store by default. The Nix daemon stores several things in the Nix store:

  • Derivations: stand-alone files suffixed with .drv such as /nix/store/<hash>-my-package.drv
  • The products of derivations: a folder containing build outputs such as /nix/store/<hash>-my-package/
  • Patches: stand-alone files suffixed with .patch such as /nix/store/<hash>-my-package.patch

Store paths

Paths in the Nix store have this structure:

        
/nix/store/ 1. Nix store prefix
sglc12hc6pc68w5ppn2k56n6jcpaci16 2. Hash part
-
my-package-1.0 3. Package name

Let's break store paths down into their constituent elements:

  1. The root path is /nix/store by default.
  2. The input hash is derived from the inputs to the derivation used to build the package
  3. The package name is provided by the package creator

Some important things to note about store paths in Nix:

  • The root path at /nix/store doesn't conflict with other standard system paths like /usr/bin.
  • The hash ensures that two packages with the same name have completely different paths if the inputs to the package differ at all. If you were to change one letter in one file in the inputs to my-package-1.0, for example, you may end up with a store path like /nix/store/1aq3wchnvv7yn0d6y1r3j129hjqmv2k3-my-package-1.0.
  • Package names are fundamentally arbitrary. You can provide whatever naming conventions you wish. If you don't want your packages to have a concept of version, you can name them my-package and distinguish based on the input hash.

Was this page helpful?