Nix builder script

The used as a builder in Hello, Nix! is reproduced below.

source $stdenv/setup


tar xvfz $src
cd hello-*
./configure --prefix=$out
make install

source $stdenv/setup interpolates the path of the stdenv in use (a dependency added by mkDerivation) and sources the setup script, which clears the environment to prevent conflicts and unexpected interactions with the underlying system.

Every attribute of the derivation is available to the builder script as an environment variable. $perl and $src point to the Nix store path for the perl argument and the location to which the sources were saved. Everything is in the store!

Sources are unpacked into a working directory under /tmp, and the build occurs in the same directory. The special $out variable corresponds to the Nix store path computed by Nix for the attributes of the derivation. Since this is an Autoconf package, we set the prefix to $out so that the builder will install the results into the store in the expected location.

Builders are run with bash’s -e option, which causes script to bail immediately on any error.