6.5 Exercise: a release.nix for GNU hello
Lesson 44 of 68 · 18:13
Video chapters
-
0:00 Reusing the Hello Tarball Exercise
-
1:51 Creating release.nix Variants
-
5:34 Overriding Compiler and Patches
-
11:10 Using finalAttrs for Conditional Dependencies
Transcript
Reusing the Hello Tarball Exercise
0:00 Okay. So it's exercise time again. This time again, we're going to use the same Hello Tarball that we already used. So you can simply reuse your code that you had so far. And the whole idea is to run the beginning again, because it's so important. We look at this multiple times now. We need to get used to that. We write our default.nix to be in normal form. Normal form means it's a function parameter header that we have there.
0:32 There's no occurrence of pkgs dot anything in our package function any longer. And then we write to release.nix function that provides the three different alternatives of our Hello World package here now. The first one is just the default. So it's kind of just normal Hello World, no patches, nothing. The second one should be built with Clang. Please mind that Hello Clang is the default on macOS. So if you're using a Mac right now, then the Clang standard environment is actually your default.
1:05 And only on Linux we switch to Clang standard environment. If you're doing this exercise on a Mac, you could just say Hello GCC and then instead call packages GCC standard environment to substitute your standard environment, because this way the difference is just clear that GCC here is the default choice on Linux and on macOS it would be Clang. Easy as that. The third variant is that we add the patches here. So this one is slightly trickier.
The full transcript comes with the lesson.
About this lesson
Time to do it yourself. You take the GNU hello package from the earlier lessons, normalize its default.nix into a package function, and write a release.nix that exposes three variants: a plain default build, a build with a different compiler, and a patched build. This is the repetition that makes override and overrideAttrs stick.
In this video
- Three package variants from one recipe, each one testing a different skill
- A destructive
overrideAttrsmistake that silently drops a security patch, and the defensive habit that prevents it - Writing overrides that survive attributes which do not exist yet, so a colleague's change next week does not break them
overrideCCas a bonus round: injecting any compiler version you like intostdenv- A first look at
finalAttrsandlib.optionalfor a package that adapts itself to downstream patches
After this lesson
Your fingers know the override workflow, not just your head. This skill is what Nix people use at work all the time, and it is the foundation for overlays later in the course.
Links:
- Exercise source (GNU hello 2.9): https://gnu.mirror.constant.com/hello/hello-2.9.tar.gz
- Solutions: https://nixcademy.com/downloads/hello-release-solution.zip