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

5.2 A minimal mkDerivation: build GNU hello yourself

Lesson 31 of 68 · 2:26

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

Video chapters

  1. 0:00 Exercise: Build the Hello Package
  2. 0:31 Downloading the Tarball and Writing mkDerivation
  3. 1:19 Pointing mkDerivation at the Tarball
Transcript

Exercise: Build the Hello Package

0:00 So, exercise time. This one will be simple, promised, because we just built a hello. Yet, yes, now that you do it yourself once to see it with your own eyes and after you wrote it with your own hands how easy that is. So, let's pick this one here, download it, and then write your own Nix expression like that to build this. And press pause now, try to kind of apply this,

Downloading the Tarball and Writing mkDerivation

0:33 and just have it work by yourself. We will try to not unpack it and actually point this to the zip file, which also works, and then we can see how the unpacking also magically happens. This is just to get familiar with it and do it yourself. Press pause now and try it yourself. Okay, so let me copy this URL, and then we can say, okay, mkdir hello derivation, and we can run wget, and now we have it here. So, with that, we can now start, oh, that was still the old editor.

Pointing mkDerivation at the Tarball

1:22 Same dance, let packages equals import, and then packages dot standard environment dot mkDerivation, name is hello, and src equals dot slash, and then the hello tarball. And that should already work.

The full transcript comes with the lesson.

About this lesson

Watching someone package software with Nix is one thing, typing the expression yourself is what makes it stick. In this short exercise you download the GNU hello tarball and write your own minimal stdenv.mkDerivation expression for it, this time pointing src straight at the archive instead of an unpacked folder. It is the quickest way to see how much mkDerivation figures out on its own.

In this video

  • Writing a complete package expression with little more than a name and a src
  • Pointing src at a tarball and watching the unpacking happen without one extra line of code
  • Why the exact same expression works for a folder and for an archive
  • A look ahead: how fetchers will later pin this download properly

After this lesson

You have packaged an upstream tarball with your own hands, and the basic mkDerivation pattern is in your muscle memory for everything that follows.

Links: