Skip to content

About

Nix & NixOS training for gambiconf 2026

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Nix Training

🌐 Read this in other languages: 🇺🇸 English | 🇧🇷 Português

Notes and tutorials for our Nix training, originally created for Gambiconf 2026.

Three-hour workshop

For the instructor-led course, follow Nix in Three Hours. It contains the required reading, hands-on checkpoints, and hard time boundaries. Instructors should also use the facilitator guide. The numbered modules below remain the extended course and reference library.

PDF slides

The instructor decks for modules 01 through 07 are authored as Markdown under slides/. The existing module notes remain the canonical, detailed material. On Linux, build the seven individual PDFs and the combined deck with:

make slides
make slides-check

make slides-preview starts Marp's local preview server. CI publishes the PDFs as a workflow artifact; generated files are not committed or added to the training image closure.

What is Nix?

Nix is a purely functional package manager. This means that it treats packages like values in a purely functional programming language — packages are built by functions that don’t have side-effects, and they never change after they have been built. Nix stores packages in the Nix store, usually the directory /nix/store, where each package has its own unique subdirectory such as

/nix/store/q06x3jll2yfzckz2bzqak089p43ixkkq-firefox-33.1/

where q06x3jll2yfz… is a unique identifier for the package that captures all its dependencies (it’s a cryptographic hash of the package’s build dependency graph). This enables many powerful features.

— Nix Reference Manual 2.35, Introduction

In plain words: every build gets its own read-only folder, and the folder's name is derived from everything that went into the build. New terms are defined in the glossary.

That one idea leads to the rest:

Property Why it holds
Multiple versions side by side different inputs → different hash → different path. No "DLL hell".
Complete dependencies no global /usr/lib. If it builds, every dependency was declared. Runtime deps are found by scanning outputs for store hashes.
Multi-user unprivileged users install safely, shared paths are built once, and there's no way to trojan another user's packages
Atomic upgrades & rollbacks nothing is overwritten. A profile symlink flips atomically, and --rollback flips it back.
Garbage collection uninstalling only unlinks. nix-collect-garbage removes what nothing uses.
Transparent source/binary deployment builds are described from source, but Nix first checks a binary cache (cache.nixos.org/<hash>.narinfo)
Dev environments nix-shell / nix develop drop you into a package's exact build environment
NixOS the same model applied to a whole Linux system: /etc, services, boot, with system-wide rollbacks

Nix runs on Linux, macOS and even Windows Through NixOS-WSL.

Modules

# Module You'll learn
00 Getting started run a flake, build a package, inspect its locked inputs
01 Nix Language types, syntax, operators, scoping, strings and context, builtins
02 Nix Store file system objects, store objects and paths, store types, profiles, GC, substituters
03 Derivations build a raw derivation, GNU Hello and a static page; debug builds
04 Development shells devShells, nix develop, lightweight tools and package build environments
05 Flakes in depth compose flakes, align inputs, update locks, expose checks
06 Nixpkgs callPackage, packaging, stdenv, overrides and overlays
07 NixOS system configuration, VMs, the module system, VM integration tests
08 Declarative Infra nixos-anywhere + disko, Terraform, running a binary cache

How to use this repo

  • For the three-hour session, follow WORKSHOP.md. For the extended course, start at 00 and work through the modules in order. Flakes are the course's interface from the first exercise; module 05 explores them in depth.
  • Each runnable exercise has a standalone flake.nix and flake.lock. Run its commands inside its directory. The root flake maintains this repository and builds the training VM.
  • Keep the supplied locks during the workshop. Examples share the root nixpkgs source and revision so cached dependencies can be reused. This pin supports x86_64 Linux, ARM64 Linux and Apple Silicon macOS; Intel Mac participants use the x86_64 guest.
  • Every note ends with the upstream Source links. The notes are condensed summaries, and the manual remains the authority.
  • Nix manual pages are cited at version 2.35, the Nix release the training guest runs (nix --version).
  • New to the vocabulary? The glossary quotes the official definitions of the terms used in the early modules.
  • Use nix build, nix run, nix develop and nix repl (:lf .) as you go. Traditional commands appear only where they help explain an existing interface or inspect low-level state.

Training VM

Download the latest boot-tested x86_64 or aarch64 qcow2 image from GitHub Releases. The QEMU image workflow builds and validates both architectures on pull requests. On main, checked images are attached directly to a run-specific draft release; only after both jobs succeed and both assets are complete is the release published and marked latest. This workflow does not use Actions artifact storage. Failed or cancelled publishing runs can leave an unpublished draft; failed-job reruns reuse it, while full reruns create a new draft for their attempt.

To build the same image locally on an x86_64 Linux host (with Nix):

nix build .#qemu-image

The Makefile detects x86_64 or ARM64 hosts and provides the matching image, interactive QEMU boot, and automated boot, SSH, offline core-exercise and web rollback checks:

make image
make run VM_MEMORY=2048
make test VM_MEMORY=2048

On Linux, make image builds the matching NixOS image. On macOS, it downloads the matching image from the latest release; make run needs QEMU, while make test also needs Nix. make run prints the guest login (gambi / gambi), forwards SSH to 127.0.0.1:2222, and discards guest changes on exit. make test uses port 2223, so both can run at once. Override VM_SSH_PORT, TEST_SSH_PORT, or VM_MEMORY on the make command line if needed. QEMU boots the image with UEFI firmware on both architectures; set VM_FIRMWARE to a firmware file if QEMU cannot find edk2-x86_64-code.fd or edk2-aarch64-code.fd in its data directory. make vm builds the local VM launcher on Linux.

For quick local experiments with Nix installed, build the VM launcher from the same guest configuration:

make vm
QEMU_KERNEL_PARAMS=console=ttyS0 ./result-vm/bin/run-nix-training-vm -nographic

The launcher uses your host's Nix store and writes guest state to nix-training.qcow2 in the current directory. The downloadable image includes its own Nix store.

Run a downloaded file directly with QEMU, or use make run to select the correct command. This example is for x86_64; for a local build, use result/nix-training-x86_64.qcow2 as the drive path:

qemu-system-x86_64 -m 2048 -machine q35 -drive if=pflash,format=raw,readonly=on,file=/path/to/edk2-x86_64-code.fd -drive file=nix-training-x86_64.qcow2,format=qcow2,if=virtio -nic user,hostfwd=tcp:127.0.0.1:2222-:22 -nographic

Log in on the console as gambi with password gambi, or connect with ssh -p 2222 gambi@127.0.0.1. The updated image creates a writable ~/nix-training workspace and preloads the pinned nixpkgs source, core exercise tools, Hello's compiler environment, the optional icat exercise and both specified web-lab system versions. Start with cd ~/nix-training/00-getting-started. Keep the supplied locks and use at least 2 GiB RAM for the NixOS lab; optional devenv needs additional downloads. The guest enables nix-command and flakes. You can also add this to ~/.ssh/config:

Host gambiconf
  Hostname 127.0.0.1
  User gambi
  Port 2222
  UserKnownHostsFile=/dev/null
  StrictHostKeyChecking=no

Then connect to the VM and enter gambi when SSH prompts for the password:

ssh gambiconf

Source: https://nix.dev/manual/nix/2.35/introduction.html

About

Nix & NixOS training for gambiconf 2026

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages