6.2 The callPackage pattern
Lesson 41 of 68 · 10:49
Up next in 5s…
About this lesson
The callPackage pattern looks like a useless indirection at first. Then you see what it enables and you never want to write a package any other way. In this lesson we turn a plain mkDerivation file into a package function, call it with pkgs.callPackage, and get the override feature that all of nixpkgs is built on.
In this video
- Rewriting
default.nixinto a normalized package function that names all its dependencies in the first line - Feature flags as function parameters, the same way nixpkgs packages do it
- Wiring the package up from a
release.nixwithcallPackageand watching Nix fill in the arguments by itself - Building the same recipe with GCC and with Clang, and why C++ teams put exactly this into their CI
- The mechanism vs policy split, and one short
pkgsCrossline that produces an ARM binary on an Intel machine without touching the build system
After this lesson
You can write package functions the way nixpkgs does, and swap a compiler, a dependency, or even the target platform without forking the recipe.