Nix 101 Course / Section 6: Composing nixpkgs: callPackage, override, project layout
Premium

6.2 The callPackage pattern

Lesson 41 of 68 · 10:49

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

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.nix into 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.nix with callPackage and 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 pkgsCross line 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.