A deep dive into how Nix builds work under the hood, demonstrated by reimplementing nix-build in under 100 lines of Go. The post shows that a Nix derivation (.drv) is simply a build plan containing a builder, arguments, environment variables, and dependencies. Realising a derivation involves recursively building input derivations, setting up a clean environment, and exec-ing the builder. The Go implementation works for both trivial and real-world derivations (e.g., nixpkgs#hello). Missing features compared to the real Nix daemon include sandboxing via Linux namespaces, the SQLite path database, binary cache substitution, and garbage collection — but the core build mechanism itself is straightforward.

5m read timeFrom fzakaria.com
Post cover image
533 Impressions