Concepts — Nix language, store, CLI, flakes

Updated

July 30, 2026

Concepts — Nix language, store, CLI, flakes

This part of the standalone NixOS book is organized by topic (normal book chapters), not by calendar day.

Read chapters in order within the part when learning; skip or skim freely when using the book as a reference.


What this part is for

Concepts builds the mental models every later part assumes: what Nix is, how the store works, how the language composes config-shaped data, how derivations become store paths, and how the modern flakes CLI pins work.

You will not install NixOS here. You will install the package manager, enable flakes, and practice evaluation, builds, and project shells on any supported host (Linux or macOS for most drills; some store demos prefer Linux).

This part Next part
Language + store + flakes literacy NixOS host — install a machine and manage it as code
Disposable experiments on any Nix install Generations, modules, firewall, boot

Baseline (this book)

Piece Baseline
Nix 2.34.x (modern CLI + flakes)
nixpkgs channel pin nixos-26.05 (Yarara) when you pin flakes
Default workflow Flakes + nix build / nix run / nix develop
Classic CLI Literacy only (last chapter of this part)

Version numbers drift in the wild; when in doubt, check nix --version and pin 26.05 in your own flakes so examples stay comparable.


Learning outcomes

By the end of this part you should be able to:

  1. Separate the three faces of Nix: language, package manager, NixOS
  2. Read a /nix/store/… path and explain closures and GC roots
  3. Write nested attrsets, let/inherit, and config-shaped data
  4. Write functions with attr-pattern args, defaults, ellipsis, and @
  5. Split multi-file Nix with laziness and a few lib pipelines
  6. Explain a derivation as a plan → .drv → realized output (including FODs at awareness level)
  7. Use the modern CLI for build/run/shell/develop/eval/path-info
  8. Author a project flake with lockfile + devShells.default
  9. Translate classic commands when reading old docs—without living there

Prerequisites

You should have Nice to have
Comfortable shell (bash/zsh) Prior package-manager pain (apt/pip/npm)
Text editor + git basics A disposable machine or VM for disk-heavy store labs
~10–20 GB free for store growth Linux (closer to later NixOS host work)

No prior NixOS install required for this part.


Chapter map

Chapter Title Focus
Why Nix exists Problem statement, three faces, install Nix, first REPL
Store and closures Path anatomy, references, closures, GC roots
Language: attrsets Values, strings, lists, sets, let, inherit, //
Language: functions Lambdas, pattern args, ?, ..., @, call shapes
Laziness, imports, lib Lazy force, multi-file, infinite recursion, lib
Derivations as an idea Plans, sandbox, FODs, trivial builds, logs
Modern Nix CLI Installables, build/run/shell/develop, flake subcommands
Flakes and devShells inputs/outputs/lock, mkShell, git discipline
Classic CLI literacy Classic ↔︎ modern map, channels vs locks

Suggested learning paths

Path Order Notes
Linear (recommended first pass) 01 → 09 Builds one model on the next
Language-first 03 → 05, then 01–02, 06–09 If you already installed Nix
Ops-curious skim 01, 02, 07, 08 Then return for language depth
Reference Any chapter standalone Use checkpoints + gotchas tables

How each chapter is structured

Topic chapters in this book generally share:

  1. Goal — what competence you leave with
  2. Why it matters — systems/ops motivation
  3. Theory — tables, mental models, diagrams when present
  4. Worked examples — adaptablesnippets (Nix 2.34 / flakes / 26.05 baseline)
  5. Labs / exercises — hands-on practice
  6. Common pitfalls — symptom → theory table
  7. Checkpoint — self-check before moving on
  8. Further depth — related chapters in this book only

Lab workspace convention

Prefer a single lab tree on your workstation (not tied to any calendar series):

mkdir -p ~/lab/nixos-book/concepts
cd ~/lab/nixos-book/concepts

Per-chapter subdirs (why-nix, store, attrsets, …) keep experiments reproducible. Commit flakes and notes; do not commit private keys or machine secrets.


Mental model map (part-level)

Expression (Nix language)
    │ evaluate
    ▼
Derivation plan (.drv)  ──realize──►  Store path(s)
    │                                     │
    │                                     ├─ references → closure
    │                                     └─ GC roots keep live
    ▼
Modern CLI / flake outputs name installables
    │
    ▼
devShell / package / (later) nixosConfigurations

Keep this sketch in mind when a command “does nothing” (eval) versus “downloads forever” (realize) versus “fills the disk” (roots).


What you will not do in this part

Out of scope here Covered later in this book
Install NixOS / UEFI / generations Part NixOS host
Home Manager, fleet, Disko Later parts
Deep stdenv packaging Packaging part
Module system authoring Host + Internals
Cross-links to any 90-day series Not used in this book

Suggested checkpoints (part gate)

Before starting the NixOS host part, confirm:

  • nix --version reports a 2.34.x-class Nix with flakes enabled
  • You can explain language vs package manager vs NixOS in one sentence each
  • You can define store path, closure, and GC root
  • You can evaluate multi-file Nix with functions and attrsets
  • You can nix build / nix run / nix develop against a personal flake
  • flake.lock is committed for that project
  • You can translate at least five classic commands to modern ones

Further depth (this book)

After Concepts… Go to
Own a machine as code Part NixOS host (02-nixos-host)
Project layout, locks, HM Part Home and flake layout
Secrets, services, TLS Part Services and security
Real packaging Part Packaging
Evaluator / module deep dive Part Internals

How to use this part as a reference

  • Sidebar titles come from each chapter’s title: frontmatter—search by topic name
  • Gotchas tables at chapter ends are optimized for “I hit this error” jumps
  • Worked examples are meant to be copied and adapted, not treated as sacred
  • Prefer pinning nixpkgs to 26.05 in examples so your lock matches the book’s baseline

When a later chapter assumes “you know closures,” it means this part—not a calendar day number.