Nix 101 Course / Section 4: How Nix actually builds: sandbox → derivation → hash → store
Premium

4.3 The derivation is just a recipe

Lesson 26 of 68 · 8:46

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

About this lesson

Every Nix build runs off a .drv file in the Nix store. In this lesson we create one with nix-instantiate, convert it to JSON, and read it line by line. It turns out a Nix derivation is a short, fully machine readable recipe, and the Nix build engine underneath is a much simpler machine than it looks from the outside.

In this video

  • Producing a derivation file without building anything, and pretty printing it with nix derivation show and jq
  • What a derivation actually contains: a builder, its arguments, an environment, input derivations and sources, and not much else
  • How referencing dependencies by derivation path turns Nix into a build scheduler that pauses your sandbox, fetches or builds what is missing, then continues
  • The one Linux system call the whole data structure maps onto, field by field
  • The two checks Nix runs at the end to decide whether your build counts as a success

After this lesson

Real world derivation files are longer, but not more complicated: more environment variables, more inputs, same shape. You can open any .drv file on your system and know what you are looking at.