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

4.4 Exercise: package mini-hello with builtins.derivation

Lesson 27 of 68 · 12:08

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

About this lesson

Time to build real software in the sandbox with your own hands. In this exercise you package mini-hello, a small C program with a Makefile, using nothing but builtins.derivation, gcc, GNU Make and coreutils. No mkDerivation, no helpers, no safety net. Working through this once is what later makes failing builds readable instead of mysterious.

In this video

  • Your mission: compile mini-hello inside the Nix build sandbox and ship the binary in $out/bin
  • The three steps you have to figure out, starting from a build folder that is completely empty, source code included
  • Hints with pause points along the way, so you get exactly as much help as you want
  • Turning your output into a first class package: install it with nix profile add, run it from anywhere, remove it again
  • Why this exercise takes people up to two hours in live trainings, and why that fight is the point

After this lesson

You have built and installed a working package with a hand written builder script. When a high level builder fails later and something is missing from the environment, you recognize the situation, because you assembled that environment yourself once.

Links: