Skip to content
Français
Sync not enabled: your progress stays in this browser My learning
Select theme
Français

Nix store, profiles and generations: understand the data model

By updated

Improve this page

The Nix store (/nix/store/) is the single directory where Nix puts everything it installs: each package lives there in a subdirectory identified by a cryptographic hash. Two identical installations produce exactly the same path, two different versions coexist without conflict. On top of it, profiles expose the binaries through symbolic links, and generations keep a complete history that allows an instant rollback. This model removes dependency conflicts, makes every operation atomic and lets you reclaim disk space on demand. The outputs of this guide were captured on Nix 2.35.2.

What you will learn

  • Understand the structure of the Nix store and the role of the hash in each path
  • Explore a package in the store and its closure (complete dependency tree)
  • Work with user profiles and see how binaries are exposed
  • Create, list and switch between generations
  • Perform an instant rollback to a previous state
  • Free space with the garbage collector and store optimisation

In what context?

When you install a package with nix profile add, you do not touch the classic system directories (/usr/bin, /usr/lib). The package lands in the store, and a symbolic link appears in your profile. Understanding this mechanism is essential to:

  • diagnose why a binary is not found after installation,
  • free disk space without breaking active packages,
  • go back after a failed update,
  • share a reproducible environment between machines,
  • understand closures to optimise the size of your deployments.

The store: /nix/store/

The store alone replaces /usr/bin, /usr/lib and /usr/share: Nix never writes into those directories. Every package it holds is read-only, and in a multi-user installation the directory belongs to root (group nixbld), even when you install a package as a normal user: the daemon writes for you. The four subsections detail its naming convention, the content of a package, the reason for its immutability and how its size evolves.

One directory, one hash

Every item of the Nix store lives in a path of the form:

/nix/store/<hash-32-characters>-<name>-<version>

The hash is computed from all the inputs of the build: source code, dependencies, build flags, patches. If one of these inputs changes, the hash changes, and a new path is created.

Terminal window
ls /nix/store/ | grep ripgrep
Result
vli6118fdbngwy46j1w741ansmrzfszr-ripgrep-15.2.0

Anatomy of a package in the store

Every store directory follows an FHS-like (but isolated) structure:

Terminal window
ls -la /nix/store/vli6118fdbngwy46j1w741ansmrzfszr-ripgrep-15.2.0/
Result
dr-xr-xr-x 4 root root 4096 Jan 1 1970 .
drwxrwxr-t 173 root nixbld 143360 Oct 1 11:58 ..
dr-xr-xr-x 2 root root 4096 Jan 1 1970 bin
dr-xr-xr-x 6 root root 4096 Jan 1 1970 share

The rg binary is in bin/, the man pages in share/. But unlike a Debian package or an RPM, nothing is copied into /usr/bin, the package lives exclusively in the store.

Store immutability

Store directories are read-only (dr-xr-xr-x). Once built, a package can no longer be modified, only deleted by the garbage collector. This immutability guarantees that no process can silently corrupt a dependency. On NixOS, the store is additionally mounted read-only; on another distribution, the file permissions provide this protection.

Store size

After a few installations, the store grows fast, because every package pulls in its dependencies, which are also copied into the store:

Terminal window
du -sh /nix/store/
Result
1.2G /nix/store/
Terminal window
ls /nix/store/ | wc -l
Result
2242

Do not worry about this size: the garbage collector (described below) lets you reclaim the space of unused packages.

Closures: the complete dependency tree

A closure is the set of all the store paths needed for a package to work. When Nix installs ripgrep, it does not just download the binary, it makes sure that all its dependencies (glibc, pcre2, gcc-lib…) are present in the store.

Terminal window
nix path-info -rsSh /nix/store/vli6118fdbngwy46j1w741ansmrzfszr-ripgrep-15.2.0
Result: ripgrep closure (55.7 MiB)
/nix/store/g60m3aky9f59wgy1gi0y06xwmbw19d6m-xgcc-16.2.0-libgcc 197.5 KiB 197.5 KiB
/nix/store/jp8ql2fnd61xhvb4vsfp0bqwrzf16qrp-libunistring-1.4.2 2.0 MiB 2.0 MiB
/nix/store/q0lbdx5yv93a3md74kjhm0v2kljjii89-libidn2-2.3.8 363.6 KiB 2.3 MiB
/nix/store/h4wfwic161kxrr74jlzla5lsm28hgary-glibc-2.44-25 33.9 MiB 36.5 MiB
/nix/store/7v8b5idfzwfl06hx6n0cvd5ikd5p0sbg-pcre2-10.48 2.0 MiB 38.5 MiB
/nix/store/q2mkz6ca1alqfqf750dygvakmq8kjrwz-gcc-16.2.0-libgcc 197.6 KiB 197.6 KiB
/nix/store/j7qx4s4mr17j1wqgvqdzj33lmrnzb387-gcc-16.2.0-lib 10.3 MiB 47.0 MiB
/nix/store/vli6118fdbngwy46j1w741ansmrzfszr-ripgrep-15.2.0 6.7 MiB 55.7 MiB

The first column of figures gives the own size of the package, the second its closure size (the package + all its transitive dependencies). Here, ripgrep weighs 6.7 MiB but its complete closure reaches 55.7 MiB, mainly because of glibc.

Profiles: exposing the binaries

A package present in the store is not executable from your shell for all that: nothing was added to your PATH. That is the job of the profile, an aggregation directory that gathers, through symbolic links, the binaries of the packages you explicitly asked for. This indirection is what makes rollback possible: changing version means repointing a single link, without copying or deleting anything.

Installing a package copies nothing into /usr/bin. Nix creates a chain of symbolic links that connects your $PATH to the store:

~/.nix-profile → ~/.local/state/nix/profiles/profile
└→ profile-2-link → /nix/store/z4q4...-profile/
└→ bin/
├── jq → /nix/store/m3y7...-jq-1.8.2-bin/bin/jq
└── rg → /nix/store/vli6...-ripgrep-15.2.0/bin/rg

Let us check on a machine where ripgrep then jq were added to the profile:

Terminal window
ls -la ~/.nix-profile
Result
~/.nix-profile -> /home/lab/.local/state/nix/profiles/profile
Terminal window
ls -la ~/.local/state/nix/profiles/
Result
profile -> profile-2-link
profile-1-link -> /nix/store/jp7s18kqhhg89mbw6yy2arlz4hydj32m-profile
profile-2-link -> /nix/store/z4q4b9x6bcmafk8fhmixc3id8rq1drzf-profile
Terminal window
ls ~/.nix-profile/bin/
Result
jq rg

Each profile-N-link points to a store directory that aggregates all the packages of that generation. When you add a package, Nix creates a new aggregation directory in the store and points the profile link to it.

System profile vs user profile

Nix manages two levels of profiles, and they have neither the same owner nor the same consequences when something goes wrong. The user profile lives in your HOME and only concerns you; the system profile holds the Nix installation itself. Remember the bottom row, it is the one that breaks a machine when it is cleaned up without thinking:

ProfilePathUsage
User~/.local/state/nix/profiles/profilePackages installed by the current user
System/nix/var/nix/profiles/defaultPackages installed for the whole system (includes nix itself)

Generations: history and rollback

Nix never modifies a profile in place: it builds a new version and moves a link. Each of these versions is a generation, numbered and kept as long as you do not delete it explicitly. Going back after a failed update therefore needs neither a backup nor a reinstallation, and takes the time of a symbolic link change.

Every change creates a generation

On every addition or removal of a package, Nix creates a new generation of the profile. The previous generation stays intact in the store, nothing is overwritten.

Let us install jq and look at the history:

Terminal window
nix profile add nixpkgs#jq
Terminal window
nix profile history
Result
Version 1 (2026-10-01):
flake:nixpkgs#legacyPackages.x86_64-linux.ripgrep: ∅ -> 15.2.0
Version 2 (2026-10-01) <- 1:
flake:nixpkgs#legacyPackages.x86_64-linux.jq: ∅ -> 1.8.2-bin, 1.8.2-man

Version 1 contains only ripgrep. Version 2 adds jq and refers to Version 1 as its parent (<- 1).

Instant rollback

To go back to the previous generation:

Terminal window
nix profile rollback
Result
switching profile from version 2 to 1

After the rollback, only rg is available in the profile:

Terminal window
ls ~/.nix-profile/bin/
Result
rg

jq has disappeared from the profile, but it is still present in the store. Nix only changed the profile symbolic link to point to profile-1-link instead of profile-2-link.

Switch to a specific generation

To go back to generation 2:

Terminal window
nix profile rollback --to 2
Result
switching profile from version 1 to 2
Terminal window
ls ~/.nix-profile/bin/
Result
jq rg

List the packages of the active profile

The output only shows the explicitly installed packages, not their dependencies. For each of them, it gives the requested source, the nixpkgs revision actually locked, and the associated store paths (here jq provides two, one for the binary, one for the man pages).

Terminal window
nix profile list
Result
Name: jq
Flake attribute: legacyPackages.x86_64-linux.jq
Original flake URL: flake:nixpkgs
Locked flake URL: https://releases.nixos.org/nixpkgs/nixpkgs-26.11pre1082290.b6c8664de9b6/nixexprs.tar.zst?narHash=sha256-k8Fu4c9Z%2B4Nh7mUr0cfw%2B%2BITQiyEhlWxoJBOkI3tOcQ%3D
Store paths: /nix/store/gpc36qrvyhyqb6axmj1c0ivx74ni7d8d-jq-1.8.2-man /nix/store/m3y7hqmy20nd1ps6qy8410a326255bf0-jq-1.8.2-bin
Name: ripgrep
Flake attribute: legacyPackages.x86_64-linux.ripgrep
Original flake URL: flake:nixpkgs
Locked flake URL: https://releases.nixos.org/nixpkgs/nixpkgs-26.11pre1082290.b6c8664de9b6/nixexprs.tar.zst?narHash=sha256-k8Fu4c9Z%2B4Nh7mUr0cfw%2B%2BITQiyEhlWxoJBOkI3tOcQ%3D
Store paths: /nix/store/vli6118fdbngwy46j1w741ansmrzfszr-ripgrep-15.2.0

Freeing space: garbage collection and optimisation

The store never empties itself, it has no automatic purge. Cleaning happens in two steps, and the order matters: first delete the old generations, which removes the references that protected the packages, then run the garbage collector, which erases what is no longer referenced. A deduplication pass then trims what remains.

Why the store grows

The store accumulates packages over time: old generations, packages tried with nix shell, intermediate build dependencies. As long as a GC root references a path, it is protected from deletion.

The main GC roots are:

  • the profile generations (profile-1-link, profile-2-link…),
  • the nix build results linked in ./result, registered under /nix/var/nix/gcroots/auto/,
  • the system profiles.

Delete old generations

Before running the garbage collector, delete the obsolete generations to remove them from the GC roots:

Terminal window
nix profile wipe-history --older-than 1d

This command deletes the generations older than one day. The active generation is always kept, even if it is older, and generations younger than one day stay too: on a profile created the same day, the command therefore deletes nothing.

Run the garbage collector

The command walks the store and deletes every path that no GC root references. It prints each deletion then a figure-based summary, and it is irreversible: an erased package will be downloaded or recompiled again if it becomes necessary.

Terminal window
nix store gc
Result (excerpt)
deleting '/nix/store/i4q069m3d29gi7dw1ijhjrp4hxw1c2l4-module-dir.patch'
deleting '/nix/store/d77svhhwwqkvacx0gdyscjp4jdfjkh9d-gcc-15.patch'
...
deleting unused links...
533 store paths deleted, 242.6 MiB freed

The GC reclaimed 242 MiB by deleting 533 paths that no root referenced any more. To know beforehand what it would delete, nix store gc --dry-run only prints the count.

Terminal window
du -sh /nix/store/
Result
660M /nix/store/

The store went from 1.2 GB to 660 MB.

Optimise the store by deduplication

Even after the GC, some files are duplicated between packages (shared libraries, identical configuration files). The optimise command replaces them with hard links:

Terminal window
nix store optimise
Result
15.2 MiB freed by hard-linking 1230 files
Terminal window
du -sh /nix/store/
Result
647M /nix/store/

Summary of the maintenance commands

Here are the four commands to remember for periodic maintenance. The first two are chained in this order; the last one, --max, is for when you want to reclaim a given amount without emptying everything that can be reclaimed.

CommandEffect
nix profile wipe-history --older-than 7dDeletes the generations older than 7 days, except the active one
nix store gcDeletes unreferenced paths
nix store optimiseDeduplicates identical files with hard links
nix store gc --max 1GFrees at most 1 GB

Summary of the data model

The diagram puts the three layers back in the order your shell goes through them. There is only one mutable link in the whole chain, the one that designates the active generation; everything below it is immutable. This asymmetry explains both the atomicity of installations and why rollback costs nothing.

The shell PATH contains ~/.nix-profile/bin, which leads to the profile link. This link, the only mutable one, points to profile-2-link, the active generation; nix profile rollback repoints it to profile-1-link. The active generation points to a store directory that gathers the binaries of ripgrep 15.2.0 and jq 1.8.2, ripgrep itself depending on glibc 2.44.     Your shell     PATH contains ~/.nix-profile/bin~/.nix-profileto ~/.local/state/nix/profiles/profileprofilethe only mutable linkprofile-2-linkactive generation points to profile-1-linkolder, rollback possible nix profile rollback /nix/store/…-profile/bingathers the binaries     ripgrep-15.2.0     in /nix/store     jq-1.8.2-bin     in /nix/store     glibc-2.44-25     in /nix/store dependency starting point: the shellprofile link or directorypackage in /nix/storepoints to or depends onrollback
Source · SVG
Esc to close, + and − to zoom, scroll to move around. 100 %

Key points

  • The store (/nix/store/) holds every package, each identified by a unique hash, two versions coexist without conflict.
  • A closure is the complete set of dependencies of a package; it is the deployment unit of Nix.
  • Profiles expose the binaries through chains of symbolic links, without touching /usr/bin.
  • Every change to the profile creates a new generation; rollback is instant and atomic.
  • The garbage collector only deletes paths without a GC root, your active packages are always protected.
  • nix store optimise deduplicates identical files with hard links to reduce the disk footprint.

Knowledge check

Check that the essentials of this guide are acquired. The questions only cover what has just been explained here.

Knowledge check

Check what you have learned with this interactive quiz

6 questions
6 min
70% to pass

How it works

  • The timer starts when you click Start
  • Multiple choice, true/false and short answer questions
  • You can move between questions
  • Detailed results are shown at the end

Starts the quiz and the timer