8.7 Exercise: patching across the dependency tree
Lesson 58 of 68 · 28:24
Video chapters
-
0:00 Introduction to overlays and the exercise setup
-
2:25 Repository structure and dependency graph
-
6:00 Patching packages with overrideAttrs
-
13:00 Refactoring the patch logic and handling errors
-
18:00 Moving the patches into an overlay
-
23:30 Overlay order, precedence, and wrap-up
Transcript
Introduction to overlays and the exercise setup
0:00 OK, so welcome to the big overlay exercise. This one is my favorite exercise in the whole training because it typically makes people like, wow, and aha, now I understand it. The thing is that overlays are a really important and powerful feature, maybe the most powerful feature in Nix packages in general. But then when you work with real life examples of it, they are very unwieldy. And changing something, experimenting leads to huge error messages. And you're like, wow, what did I do wrong here?
0:31 And then this exercise here, we have this all on very small scale. We do all the tricks that we typically see in the wild on larger scale, but in small. So this is very nice for experimentation. Let's play around with that. We will clone this repository. And let's look first what is inside, then revisit this slide here to see what we actually want to do. And, yeah, we can clone this.
1:02 And then when we're inside, I also added direnv. We won't really need that. What do we have? We have folders A, B, C, D, and app. And each of them will be one package. And then we also have a dependency tree. Let me open that on the side. So let me park that up here.
The full transcript comes with the lesson.
About this lesson
The favorite exercise of the whole course, and the one where overlays usually click. You get a miniature repository: a small app that prints ABCD through a multi-level tree of four C++ libraries, and your job is to make it print XYZW. Every trick you would need on a huge real dependency tree appears here in a size you can actually experiment with.
In this video
- A five package repo (
libAthroughlibDplus the app) that mimics a real multi-level dependency tree, no C++ knowledge required - Part one: patch all four libraries using only
overrideandoverrideAttrs, and feel how the chain grows the deeper the dependency sits - Part two: reach the same result with a single overlay, and see what suddenly comes for free, static and cross builds included
- Why
substituteInPlacewith a failing replace mode saves you from patches that silently stop applying, including one trap built into the repo on purpose - Experiments to run afterwards: reorder the overlays, predict what breaks, and find out why one broken definition never even becomes an error
After this lesson
You have patched a dependency at every depth of a tree, both surgically and globally, and you know the trade-offs of each route. Real life overlays are just this, at larger scale.
Builds on: final vs prev: the two rule flavors (8.5)
Links:
- Exercise repository: https://github.com/nixcademy/multi-project-repo
- Solution branch for part 1 (overrides): https://github.com/nixcademy/multi-project-repo/tree/solution-1
- Solution branch for part 2 (overlay): https://github.com/nixcademy/multi-project-repo/tree/solution-2