Nix Store
2 min read

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:

bash
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:

bash
nix-store --query --all

• Show what a store path depends on:

bash
nix-store --query --references /nix/store/<hash>-<name>

• Show what depends on a store path (reverse dependencies):

bash
nix-store --query --referrers /nix/store/<hash>-<name>

• Inspect its closure (dependencies):

bash
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:

bash
nix-collect-garbage

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

• Aggressive cleanup:

bash
nix-collect-garbage -d

Deletes all old generations of profiles, freeing maximum space.

• List what would be collected without deleting:

bash
nix-store --gc --print-dead

• List what is still alive (referenced):

bash
nix-store --gc --print-live