5.9 Language-specific builders: Python, Go, and Rust with Nix
Lesson 38 of 68 · 8:01
Video chapters
-
0:00 High-level Nix build helpers overview
-
1:08 Using the nixpkgs manual for language support
-
2:25 Python package builders and finalAttrs
-
4:32 Go module builds and vendor hashes
-
6:23 Rust package builds and lock files
Transcript
High-level Nix build helpers overview
0:00 Okay, so we practically already have everything, right? With mkDerivation we can practically build anything, we do understand how to manipulate the calls so that we can control what's in the sandbox, what is being run in which phase, we can override patch stuff and so on, and we can pin it and make it build forever. Of course, this is just part of the whole Nix story. We're going to learn about the high level abstractions now. So we practically understand those two things here now, and now it's time to learn about all the helpers, because if you use Go all the time, then you will want to use higher level abstractions for that, where you don't have to reinvent how to compile a Go application again and again.
0:48 Same with Rust, same with Python, same with whatever. And, of course, the thing is like if you never did Rust, then I don't need to annoy you in this video how to do Rust, same with Go programmers and so on, so this will be more of an overview. What is interesting is that nixpkgs comes with roughly 50 language specific builders and frameworks. This number doesn't age well. Of course, while you're listening to this video, it might have been already more. However, it doesn't really change the story that all those ecosystems, they come with their own helper functions.
Using the nixpkgs manual for language support
1:23 And the whole idea is that you go to nixos.org/manual/nixpkgs and there they have a chapter about language support. So let's have a look at that. We can go to the nixos manual, kind of right, and when we scroll down on the standard environment, which we practically learned about already, build helpers. We will learn about trivial build helpers and so on. We already had a look at Fetchers. What's interesting is languages and frameworks.
The full transcript comes with the lesson.
About this lesson
Nobody packages a Python, Go, or Rust project with raw mkDerivation. nixpkgs ships around 50 language specific builders for that, and they all follow one pattern. This lesson walks through buildPythonPackage, buildGoModule, and buildRustPackage so that the wall of text in the nixpkgs manual turns into a quick reference you can apply to any tech stack in minutes.
In this video
- Where language support lives in the nixpkgs manual, and how to get productive from a few pages of it
buildPythonPackagewithfetchPypi,pnameandversion, and the one default that is the opposite of plainmkDerivation- The
finalAttrspattern: why these examples avoidrec, and how a package can react to future overrides of itself buildGoModuleand itsvendorHash: what setting it to null means, and the fake hash trick for filling it inbuildRustPackageand the lock file that lets Nix synthesize every dependency download as a fixed output derivation
After this lesson
When someone hands you a project in a language you have never packaged, you know which builder to reach for, how its fetcher and hash fit together, and which manual chapter covers the rest.
Links: