C.W.K.
Stream
Lesson 04 of 05 · published

The Store, Generations, Flakes, nix-darwin

~13 min · nix, concepts, internals

Level 0Newbie
0 XP0/55 lessons0/16 achievements
0/80 XP to next level80 XP to go0% complete

Four concepts are enough to read most Nix output and most Nix flakes. Past those four you can grow as needed.

The Nix Store (/nix/store). Every package, every version, every variant lives in /nix/store/<hash>-<name>/. The hash is computed from the entire build recipe — every input, every dependency, every flag. This is why two builds can never collide: different inputs produce different hashes, so they get different paths.

Generations and rollback. Every install or upgrade creates a new numbered 'generation' of your user profile. nix-env --rollback moves the active pointer back one generation — instant, atomic, undoable. List generations with nix-env --list-generations; jump to any specific one with nix-env --switch-generation <n>.

Flakes are the unit of Nix project structure. A flake.nix declares inputs (the nixpkgs version you depend on, other flakes you use) and outputs (dev shells, packages, NixOS modules, apps). A flake.lock sits next to it and pins the exact versions of every input — the same reproducibility guarantee as package-lock.json or uv.lock, but for entire dev environments.

nix-darwin is a Nix module set for macOS. With nix-darwin you declaratively manage your entire Mac — installed packages, Dock arrangement, Finder preferences, Homebrew casks, services, login items — all in version-controlled Nix code. Apply changes with darwin-rebuild switch. It's the most ambitious dotfiles setup imaginable, and it's reproducible across Macs.

Code

Inspect the Nix store and generations·bash
# Look at the store
ls /nix/store/ | head
# Each entry is <hash>-<name>-<version>

# Your active user profile
ls -la ~/.nix-profile
# -> /nix/var/nix/profiles/per-user/$USER/profile

# List generations
nix-env --list-generations
#   1   2026-04-01 ...
#   2   2026-04-15 ... (current)
#   3   2026-05-03 ... (current)

# Roll back to a previous generation
nix-env --rollback

# Or jump to a specific one
nix-env --switch-generation 2
flake.lock — the reproducibility seal·json
// Auto-generated by 'nix flake update'. Pinned to exact commits.
{
  "nodes": {
    "nixpkgs": {
      "locked": {
        "lastModified": 1714389366,
        "rev": "6a5b8...",
        "type": "github",
        "owner": "NixOS",
        "repo": "nixpkgs"
      }
    }
  },
  "root": { "inputs": { "nixpkgs": "nixpkgs" } },
  "version": 7
}

External links

Exercise

Run 'nix-env --list-generations' (you'll have at least one). Even if you've barely used Nix, the 'generations' concept clicks once you see your own list. Read the timestamps — each one is a snapshot you can return to.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.