Nix Store

The Nix store is the central database of Nix. It is usually located at /nix/store and contains every package, configuration, and build artifact that Nix has produced.

Each entry in the Nix store has a content-addressed path of the form:

/nix/store/<hash>-<name>
  • Hash: a cryptographic hash that uniquely identifies the build output, based on all its inputs.
  • Name: a human-readable name (often package-version).

This design makes the store immutable, reproducible, and conflict-free — multiple versions of the same software can coexist without interference.

Usage

The nix-store command lets you directly inspect and manipulate the Nix store. While most users interact with it indirectly (through nix, nixos-rebuild, or nix-env), it’s useful for low-level operations.

Querying the Store

  • Show all store paths currently present:

    nix-store --query --requisites /run/current-system

    This prints the closure (all dependencies) of your current system configuration.

  • Print all store paths known to the system:

    nix-store --query --all
  • Show what a store path depends on:

    nix-store --query --references /nix/store/<hash>-<name>
  • Show what depends on a store path (reverse dependencies):

    nix-store --query --referrers /nix/store/<hash>-<name>
  • Inspect its closure (dependencies):

    nix-store --query --requisites /nix/store/<hash>-<name>

Garbage Collection

Because the store is immutable, old and unused paths accumulate over time. Nix provides garbage collection (GC) to safely remove unreferenced paths.

  • Run garbage collection:

    nix-collect-garbage

    Removes unused store paths not reachable from any user or system profile.

  • Aggressive cleanup:

    nix-collect-garbage -d

    Deletes all old generations of profiles, freeing maximum space.

  • List what would be collected without deleting:

    nix-store --gc --print-dead
  • List what is still alive (referenced):

    nix-store --gc --print-live