8.2 Overlay basics: your first overlay.nix
Lesson 53 of 68 · 3:05
Video chapters
-
0:00 Basic Nix Overlay Concept
-
0:55 Applying an Overlay to pkgs
-
1:50 Why Overlays Make Packages Portable
Transcript
Basic Nix Overlay Concept
0:00 So let me show you the most basic overlay possible. We create a new file, for example overlay.nix. It doesn't have to be in the file, but it makes sense. That file typically has a function in it that takes final and prev. Final and prev for now will just be versions of nix packages of the pkgs attribute and you'll later learn how to distinguish them and why it's two. However, after we were called with two versions of nix packages, what we return is an attribute set that explains what we lay over the existing packages attribute.
0:40 So that's kind of why it's called an overlay. What this does here, imagine there is no packages.app attribute first and after applying this overlay we get one. So nix packages without our overlay contains 100,000 packages roughly and after applying
Applying an Overlay to pkgs
0:56 this overlay we have 100,001 package. How does it look like in action? How do we install such an overlay? We import nix packages as we always do, but now we use the overlays configuration parameter here which is a list so you can add multiple overlays if you like. In this case we just import this overlay file here and then by doing that we get this packages attribute that now contains packages.app, easy as that.
The full transcript comes with the lesson.
About this lesson
Your first working overlay: a small overlay.nix file that adds a package to nixpkgs so it looks and feels like it was always there. You learn the final: prev: function shape, how to pass overlays when importing nixpkgs, and a strong reason to define your packages in overlays instead of directly in your flake.nix.
In this video
- The smallest possible overlay: one file, one function, one new attribute on top of roughly 100,000 existing packages
- Why it is called an overlay: what the returned attribute set actually lays over
- Installing it through the
overlaysparameter when importing nixpkgs - How the line between upstream packages, third party libraries, and your internal code disappears
- The free bonus:
pkgsStaticandpkgsCrossvariants of your package appear automatically
After this lesson
You can add your own packages to nixpkgs through an overlay and consume them like first class packages, with flakes or without.