2.10 How to import nixpkgs, and what the empty braces mean
Lesson 17 of 68 · 7:15
Video chapters
-
0:00 Ways to Import Nixpkgs
-
1:24 Why Nixpkgs Needs an Empty Attribute Set
-
3:06 Configuring Unfree Packages
-
4:42 What nixpkgs Points To
-
6:12 Nixpkgs as a Function and Next Steps
Transcript
Ways to Import Nixpkgs
0:00 Okay, maybe we already have enough and are fed up from the dry dock exercises with the Nix language. Let's play around with it. Let's use it for something useful. For example, for importing Nix packages, the biggest package collection in the world. There's actually multiple ways to do this and in the REPL you can run either of those. For example, we can say our packages attribute set with those 100,000 packages inside is import and then we import the Nix packages check out.
0:32 We can clone it from Git and then use it or we use this angled brackets syntax. That is typically like a magical symbol that points into some fresh Nix packages check out in the Nix store, but it can point anywhere. However, there's also the builtins getFlake function that will ask for a flake called nixpkgs, so there's on GitHub a JSON document that maps multiple names of different flakes to Git repositories and that will also point us to github.com/nixos/nixpkgs.
1:09 That's basically the output point to some checkout of Nix packages, be that somewhere in our home folder or read only somewhere in the Nix store. Typically you will end up having multiple copies of Nix packages on your disk anyway and you can import from all of them.
The full transcript comes with the lesson.
About this lesson
Almost every real Nix expression starts the same way: importing nixpkgs, the biggest package collection in the world. But why does import <nixpkgs> {} end in a pair of empty braces? This lesson answers that question, shows the different ways to get nixpkgs onto your machine, and puts the answer to work on unfree packages.
In this video
- Three ways to import nixpkgs: a local git checkout, the angle bracket path, and
builtins.getFlake - What nixpkgs actually evaluates to, and why the empty attribute set has to be there
- Passing
config.allowUnfreeso packages like Steam evaluate at all - The licensing reason nixpkgs makes unfree packages opt-in (it involves the public cache)
- A peek at what else that configuration attribute set will do for you later, from overlays to cross-compilation
After this lesson
You know what really happens on the first line of nearly every Nix file, and you can import nixpkgs with exactly the configuration you need.
Builds on: Nix syntax: the complete tour (2.3)
Links: