8.5 final vs prev: the two rule flavors
Lesson 56 of 68 · 12:22
Video chapters
-
0:00 How overlays relate to fixpoint graphs
-
1:28 Using final and prev in overlay chains
-
3:43 Two overlay rule flavors explained
-
7:18 Why the rule flavors exist and when to use them
Transcript
How overlays relate to fixpoint graphs
0:00 Okay, now after we discussed how this fixpoint function works, let's have a closer look how overlays built on top of that. As we have just seen, fixpoint functions in Nix are just a nice way to elegantly describe directed acyclic graphs and that's it. No recursion, no laziness, nothing really involved, it's just graphs and memory. And how does this work with this weird final and prev thing?
0:30 We have seen that we have been sometimes using prev instead of, I mean, both are versions of packages, right? But when we call prev callPackage, why wouldn't it be final callPackage or why wouldn't it be prev callPackage? Both would actually work and in different scenarios you would take different ones. We have also seen that when overriding one package with itself, we need to take prev, otherwise it would be infinite recursion, as we will see soon. And in other cases, we wildly switched around between prev and final.
1:04 So how would I know that? What's the secret here? That's actually pretty easy. When we look at how overlay functions are applied, this graph works. You can also find this in the NixOS wiki, I initially created my own version because I prefer those final and prev names, now they use it there too. The whole idea is that main is practically just the main overlay, so to say, from Nix
The full transcript comes with the lesson.
About this lesson
Both final and prev are versions of nixpkgs, so which one do you write in your overlay? Even experienced Nix people give contradicting answers in the forums, and there is a reason: two competing rule sets exist. This lesson shows where the two references come from in the overlay application graph, then lays out both flavors so you and your team can pick one and stay consistent.
In this video
- The overlay application graph: where
prevandfinalpoint when several overlays stack on top of nixpkgs - The one combination that always ends in infinite recursion, traced on the graph
- Flavor one, graph preserving:
prevby default,finalonly when referencing one package from another - Flavor two, everything is overridable:
finalby default,prevonly when overriding a package with itself - The grafting idea behind flavor one, the nixpkgs pull request that never got merged, and which flavor most teams actually choose today
After this lesson
You never guess between final and prev again. You apply one rule flavor consistently and can explain the trade-off behind the choice to your team.