8.4 Fixpoint recursion: how overlays really work
Lesson 55 of 68 · 16:39
Up next in 5s…
About this lesson
lib.fix looks like the snake biting its own tail: a function applied to its own result. This lesson takes fixpoint recursion apart in the REPL and on the drawing board until nothing is left but pointers and thunks. It is the exact mechanism nixpkgs overlays are built on, and understanding it puts you in a fairly small group of Nix users.
In this video
- The three line definition of
fixand why it feels like time traveling at first - Building an attribute set where
yandzare computed fromself, step by step in the REPL - Breaking it on purpose: which self references cause infinite recursion, and why the untouched attributes keep working anyway
- How Nix detects infinite recursion instantly instead of spinning forever
- The reveal: no magic and no endless loops, just an elegant way to describe a directed acyclic graph in memory, and nixpkgs is one giant such graph
After this lesson
The final: prev: shape of overlays stops looking alien. You can predict which expressions evaluate, which recurse forever, and why lazy evaluation makes the whole thing cheap.
Builds on: Lazy evaluation (2.11)