Nix builder script
The build.sh
used as a builder in Hello, Nix!ᛦ is reproduced below.
source $stdenv/setup
PATH=$perl/bin:$PATH
tar xvfz $src
cd hello-*
./configure --prefix=$out
make
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.