8.6 Composing overlays
Lesson 57 of 68 · 2:41
Video chapters
-
0:00 Why Use Multiple Overlays
-
0:42 Combining Overlays for Testing
-
1:44 Inspecting Nix Overlay Internals
Transcript
Why Use Multiple Overlays
0:00 So this one is a very short one, but I wanted to show you once what else is possible with overlays. Because you might ask yourself like, OK, so why would we even have multiple overlays, right? That might be confusing for someone if they want to use overlays. And then we're like, let's go back to the example, have to add like 15 overlays into this list. Like, why would you do that? And maybe you actually don't, but it could be possible to say, OK, look, that we have like an overlay one that defines our product packages, whatever, and that's for production.
0:39 Then we have overlay two, which maybe patches all the products to add debug symbols or log extra data, whatever.
Combining Overlays for Testing
0:50 I mean, you can with override and overrideAttrs, you can inject whatever you like, right? And then you could say, OK, let's have a testing overlay that looks like the original one alone, but it actually combines overlay one and two. And then that is the one that you use for testing. And then your product in tests, for example, the integration test that we do in the Nix 101, which is quite the killer feature, produces more test data. And then you can swap out this one versus this one.
The full transcript comes with the lesson.
About this lesson
Why would anyone pass a list of 15 overlays to nixpkgs? Because overlays compose. This short lesson shows how separate overlays for production packages and debug instrumentation combine into a testing overlay, and how a whole list of overlays collapses into one that behaves like a single final: prev: function.
In this video
- One overlay for your product packages, a second that patches them with debug symbols and extra logging
- A testing overlay that is nothing but the two combined, so integration tests run against the instrumented build
- Swapping the plain overlay against the combined one to find out whether your debug changes break the tests
- Merging many overlays into one function, so consumers never see how many are behind it
- Where to read on:
lib/fixed-points.nixin the nixpkgs repository
After this lesson
You can package customizations as exchangeable building blocks, combine them per environment, and hand users a single overlay that hides the composition.
Builds on: Overlay basics (8.2)