6.3 How callPackage actually works
Lesson 42 of 68 · 8:17
Video chapters
-
0:00 Introduction to callPackage and overrides
-
0:39 Using callPackageWith in the REPL
-
2:29 Automatic argument filling and unknown parameters
-
4:20 Returning attribute sets and using override
Transcript
Introduction to callPackage and overrides
0:00 Okay, so in a little whirlwind tour we just introduced the callPackage pattern and showed off a little bit how we can use the override function which comes out of this. If you found this a little bit too magic, this video is right for you. Let's play with that feature in the REPL. So the thing is callPackage is a function that takes another function, you would call it a higher order function in functional programming or maybe in general programming, however, where you can kind of simulate this with a simpler function.
0:38 We try to resemble here the package function that just takes parameters like x, y, z and
Using callPackageWith in the REPL
0:45 then does something with them. That is kind of similar like this where we take parameters like x, y, z and then do something with them. But this variant here is much like a whiteboard variant that's much simpler. And then there's interestingly the callPackageWith function. Packages dot lib dot callPackageWith can create us a callPackage function object so to say with the pre-selection of variables that exist. So let's say we pre-load it with x equals one and y equals ten.
The full transcript comes with the lesson.
About this lesson
If callPackage felt like magic in the last lesson, this one takes the magic apart. We rebuild the mechanism in the Nix REPL with lib.callPackageWith and tiny toy functions, so you see exactly where the auto-filled arguments come from and where the override attribute on every package is born.
In this video
- callPackage as a higher-order function, shown with a whiteboard-sized example instead of a real package
- Preloading
callPackageWithwith a small attribute set and watching it fill in function parameters - What happens with an unknown parameter, and how the error message helps you
- Where the
overridefunction on the result comes from, what it remembers, and how to chain it overrideDerivation: the legacy attribute you will meet in old docs and should ignore
After this lesson
You can explain in one sentence what pkgs.callPackage really is, and you can predict what any override call will do instead of trying things until they work.