Nix 101 Course / Section 5: Packaging real software with stdenv.mkDerivation
Premium

5.3 What stdenv ships: default tools, buildInputs, and nativeBuildInputs

Lesson 32 of 68 · 8:14

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

Video chapters

  1. 0:00 Standard Environment Overview
  2. 1:12 What mkDerivation Already Provides
  3. 2:51 Build Inputs vs Native Build Inputs
  4. 5:09 Propagated and Check Inputs
  5. 6:36 Using the Nix Manual for Reference
Transcript

Standard Environment Overview

0:00 Okay, so during our first steps with built-ins derivation, we have seen that we have to enter every and any dependency from bash to coreutils and everything. Now in the last exercise with mkDerivation, we've seen that we didn't have to enter anything. From GNU Hello, you know that it needs a compiler, it needs GNU Make, it needs a bash and tar to unpack stuff and so on. And that obviously was already part of mkDerivation, otherwise we could not have written it like that, right? So how do we know what is part of the standard environment? When you look through the documentation and through the code, you will see that it of course contains a bash. That is very important because bash is practically still the standard process that is being run in sandbox and it starts the standard builder shell script that is part of mkDerivation. With all the intelligence of finding out the files and running configure make and stuff like that, which also works in other build systems. Then there's a C compiler. On Linux, that's interesting. That's kind of the GNU C compiler collection with C and C++ support. And on macOS, that's Clang, because

What mkDerivation Already Provides

1:14 Clang is the typical compiler for the Darwin operating system. They just picked that. The rest of the tools are basically GNU variants of coreutils, ls, mkdir, rm, whatnot, right? The find command, the diff command and patch commands. This is interesting because very often packages are also patched. patchelf is an application that is being run on the latest stage in the so-called fix up phase that we will get to soon. And awk, grep, sed, these tools are typically used to change stuff like text substitution, very often in the patch phase. All the unzipping and untarring tools for the unpack phase and GNU Make is also part of it. And this is kind of the residuum, the minimal set of packages that is typically part of all the derivations, because it doesn't really hurt to have them there. So Nix does a little compromise between putting, like, with all these things, if you sometimes don't need them, then your sandbox is not minimal, of course, right? At the same time, Nix packages project builds like 100,000 different packages, and it would be simply annoying and more work to have to add the basics again and again.

2:32 And what's interesting is that if we need to add more dependencies, there's different parameters of mkDerivation. We can set buildInputs. So a build input is basically a dependency, and there are different categories of that. So right now, if you want to just add another library,

The full transcript comes with the lesson.

About this lesson

You never listed gcc, make, bash, or tar in your package, yet the build worked. This lesson shows what the Nix standard environment (stdenv) ships out of the box, and which mkDerivation parameters add the dependencies it does not include. You also learn the difference between buildInputs and nativeBuildInputs, a distinction many packages in the wild get wrong.

In this video

  • The exact toolset inside every stdenv sandbox: shell, compiler, coreutils, patching and unpacking tools
  • Why Linux and macOS builds get different C compilers
  • buildInputs vs nativeBuildInputs: where libraries like OpenSSL go, where build tools like CMake go, and why mixing them up bites you later during cross-compilation
  • Packages that forget their own dependencies (scripting languages, this one is about you), and the parameter that fixes it
  • Finding the dependency chapter in the nixpkgs manual, and why Google will not find it for you

After this lesson

You know what is already in the sandbox before your build starts, and you can add a library or a build tool to a package without guessing which parameter it belongs in.

Links: