Building Autonomous Coding Agents with Nix
Build a reproducible agent lab on your Mac, move it to disposable Linux, and make tests govern every change. Nix, devenv, bounded Ralph loops, CI, and NixOS VM tests.
TUTOR WITH THEFOCUS.AI
Copy this prompt into Claude, ChatGPT, or any external AI assistant. It points the assistant to the course instructions and links it to your student profile to track your progress and customize observations.
You are not enrolled yet. Enroll to generate a Student ID to track lesson completions and store learning notes.
Building Autonomous Coding Agents with Nix
4 parts · 12 chapters · MacBook first, Linux for unattended work
You can give an agent a clear task and still lose hours to missing tools, drifting dependencies, weak tests, and accidental access to the rest of your machine. This course builds the environment and verification loop around the agent, one observable contract at a time.
The result is a small task-board project with locked development dependencies, a PostgreSQL integration check, a precise completion feature, and a bounded agent controller. You prove the same reviewed commit on Mac and Linux, then test a Linux service across two NixOS machines.
What You’ll Build
- A Nix/devenv environment with explicit dependencies and a committed lock.
- Unit, formatting, lint, and database checks behind
devenv test. AGENTS.md, a behavior spec, an implementation plan, and a focused prompt.- A supervised agent change and a finite Ralph-style loop with time, turn, and cost controls.
- A disposable Linux worker whose credentials and lifetime are limited outside the agent.
- A Mac/Linux CI matrix and a two-node NixOS VM test with a deliberate red/green experiment.
The Spine
locked tools → tested behavior → real service → precise spec
→ supervised agent → bounded worker → cloud parity → system tests
Tests supply evidence, not omniscience. Nix supplies reproducible dependency definitions, not agent isolation. The course makes those distinctions practical rather than hiding them behind an “autonomous” label.
Course Structure
| Part | Chapters | What you prove |
|---|---|---|
| Reproducible Foundations | 01–03 | The declared tools work and the verifier catches a defect |
| Services and Contracts | 04–06 | The database check is repeatable and the next feature has testable acceptance |
| Controlled Agents | 07–09 | A reviewed change, finite retry behavior, and an actual worker boundary |
| Cloud and System Tests | 10–12 | The same source/lock passes supported hosts and a network test catches a firewall defect |
What You Need
Comfort with a terminal, Git branches, and reading a small Python function. No prior Nix or NixOS experience is required. You need permission to install Nix on your Mac, disk space for dependency downloads, and network access to upstream package sources.
Parts 1–2 require no model spend. Part 3 uses a coding-agent account; the scripted example uses a scoped Anthropic API key. Part 4 needs a disposable Linux machine or an existing suitable runner. The final VM lab targets x86 Linux with KVM. Do not buy cloud resources until you understand the architecture and teardown gates. Learners without cloud access can finish the local work and clearly mark the cloud gates incomplete.
Plan roughly 12–20 focused hours across several sessions, plus downloads and debugging. This is an estimate, not a promised completion time.
Download the Lab
Download the complete starter lab. Read its README before running anything. The baseline application works; the task-completion enhancement is intentionally absent. Acceptance tests for that enhancement are enabled in Chapter 06.
The starter is a bootstrap, not a claim of a pre-frozen environment. Chapter 02 generates and commits your actual devenv.lock; Chapter 07 records an agent package revision; Chapter 12 creates the NixOS flake lock. Later clones use those exact files. Never invent lock hashes or substitute a moving branch silently.
How Tutoring Works Here
Use the site’s tutor prompt on each lesson. Explain the mechanism first, answer the concept check, and show the result at each gate. The answer key is a grading aid; attempt the questions before opening it. Every lesson closes with a check of understanding and pass criteria.
Inspiration and Currency
Inspired by Geoffrey Huntley’s Nix/devenv discussion and Ralph loop. This course adds its own toy application, exercises, bounded controller, and validation gates. It is not affiliated with or endorsed by Huntley.
Technical references were reviewed on October 12, 2026. CLI flags, installers, packages, and hosted runners evolve. Each installation gate verifies the installed tool before relying on it. A finished site build is not proof that every learner’s cloud or Nix environment has been executed; the course requires evidence at those gates.
01 reproducible foundations
Separate reproducible dependencies from isolation, then install and verify Nix without replacing macOS.
Create a devenv project, declare tools, freeze its inputs, and prove what the lockfile does.
Run a deterministic application suite and prove the gate catches a deliberate defect.
02 services and contracts
Start PostgreSQL through devenv and test a transaction without leaving persistent test data.
Use targeted tasks for fast feedback and configure direnv with an explicit trust boundary.
Define a feature before prompting and create a reviewed, failing acceptance test before the agent changes the implementation.
03 controlled agents
Pin an agent CLI, inspect its permissions, and run one supervised implementation attempt.
Inspect a finite controller that restarts context, checks real outcomes, and stops on failure conditions.
Build and verify a disposable worker boundary before granting unattended shell access.
04 cloud and system tests
Run the same locked commit on Mac and Linux, then classify differences instead of hiding them.
Make pull requests prove the lab on Mac and Linux, and add cache trust deliberately.
Boot two NixOS machines, verify a service across their network, and finish with an evidence-based capstone.