2014-08-27 16:41:09 +00:00
|
|
|
<section xmlns="http://docbook.org/ns/docbook"
|
|
|
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
|
|
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
|
|
version="5.0"
|
|
|
|
xml:id='sec-generic-builder'>
|
|
|
|
|
|
|
|
<title>Generic Builder Syntax</title>
|
|
|
|
|
|
|
|
<para>Recall from <xref linkend='ex-hello-builder' /> that the builder
|
|
|
|
looked something like this:
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
PATH=$perl/bin:$PATH
|
|
|
|
tar xvfz $src
|
|
|
|
cd hello-*
|
|
|
|
./configure --prefix=$out
|
|
|
|
make
|
|
|
|
make install</programlisting>
|
|
|
|
|
|
|
|
The builders for almost all Unix packages look like this — set up some
|
|
|
|
environment variables, unpack the sources, configure, build, and
|
|
|
|
install. For this reason the standard environment provides some Bash
|
2020-07-23 11:58:49 +00:00
|
|
|
functions that automate the build process. Here is what a builder
|
|
|
|
using the generic build facilities looks like:</para>
|
2014-08-27 16:41:09 +00:00
|
|
|
|
|
|
|
<programlisting>
|
2020-07-23 11:58:49 +00:00
|
|
|
buildInputs="$perl" ①
|
2014-08-27 16:41:09 +00:00
|
|
|
|
2020-07-23 11:58:49 +00:00
|
|
|
source $stdenv/setup ②
|
2014-08-27 16:41:09 +00:00
|
|
|
|
2020-07-23 11:58:49 +00:00
|
|
|
genericBuild ③</programlisting>
|
2014-08-27 16:41:09 +00:00
|
|
|
|
2020-07-23 11:58:49 +00:00
|
|
|
<para>Here is what each line means:
|
2014-08-27 16:41:09 +00:00
|
|
|
|
2020-07-23 11:58:49 +00:00
|
|
|
<orderedlist>
|
|
|
|
|
|
|
|
<listitem>
|
2014-08-27 16:41:09 +00:00
|
|
|
|
2020-07-23 08:38:19 +00:00
|
|
|
<para>The <literal>buildInputs</literal> variable tells
|
2014-08-27 16:41:09 +00:00
|
|
|
<filename>setup</filename> to use the indicated packages as
|
|
|
|
<quote>inputs</quote>. This means that if a package provides a
|
|
|
|
<filename>bin</filename> subdirectory, it's added to
|
2020-07-23 08:38:19 +00:00
|
|
|
<literal>PATH</literal>; if it has a <filename>include</filename>
|
2014-08-27 16:41:09 +00:00
|
|
|
subdirectory, it's added to GCC's header search path; and so
|
2020-07-24 09:43:44 +00:00
|
|
|
on. (This is implemented in a modular way:
|
|
|
|
<filename>setup</filename> tries to source the file
|
2020-07-23 12:28:05 +00:00
|
|
|
<filename><emphasis>pkg</emphasis>/nix-support/setup-hook</filename>
|
2014-08-27 16:41:09 +00:00
|
|
|
of all dependencies. These “setup hooks” can then set up whatever
|
|
|
|
environment variables they want; for instance, the setup hook for
|
2020-07-23 08:38:19 +00:00
|
|
|
Perl sets the <literal>PERL5LIB</literal> environment variable to
|
2014-08-27 16:41:09 +00:00
|
|
|
contain the <filename>lib/site_perl</filename> directories of all
|
2020-07-24 09:43:44 +00:00
|
|
|
inputs.)
|
2014-08-27 16:41:09 +00:00
|
|
|
</para>
|
|
|
|
|
2020-07-23 11:58:49 +00:00
|
|
|
</listitem>
|
2014-08-27 16:41:09 +00:00
|
|
|
|
2020-07-23 11:58:49 +00:00
|
|
|
<listitem arearefs='ex-hello-builder2-co-2'>
|
2014-08-27 16:41:09 +00:00
|
|
|
|
|
|
|
<para>The function <function>genericBuild</function> is defined in
|
|
|
|
the file <literal>$stdenv/setup</literal>.</para>
|
|
|
|
|
2020-07-23 11:58:49 +00:00
|
|
|
</listitem>
|
2014-08-27 16:41:09 +00:00
|
|
|
|
2020-07-23 11:58:49 +00:00
|
|
|
<listitem arearefs='ex-hello-builder2-co-3'>
|
2014-08-27 16:41:09 +00:00
|
|
|
|
|
|
|
<para>The final step calls the shell function
|
|
|
|
<function>genericBuild</function>, which performs the steps that
|
|
|
|
were done explicitly in <xref linkend='ex-hello-builder' />. The
|
|
|
|
generic builder is smart enough to figure out whether to unpack
|
|
|
|
the sources using <command>gzip</command>,
|
|
|
|
<command>bzip2</command>, etc. It can be customised in many ways;
|
2014-12-14 00:39:32 +00:00
|
|
|
see the Nixpkgs manual for details.</para>
|
2014-08-27 16:41:09 +00:00
|
|
|
|
2020-07-23 11:58:49 +00:00
|
|
|
</listitem>
|
|
|
|
|
|
|
|
</orderedlist>
|
2014-08-27 16:41:09 +00:00
|
|
|
|
2020-07-23 11:58:49 +00:00
|
|
|
</para>
|
2014-08-27 16:41:09 +00:00
|
|
|
|
|
|
|
<para>Discerning readers will note that the
|
2020-07-23 08:38:19 +00:00
|
|
|
<literal>buildInputs</literal> could just as well have been set in the Nix
|
2014-08-27 16:41:09 +00:00
|
|
|
expression, like this:
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
buildInputs = [ perl ];</programlisting>
|
|
|
|
|
|
|
|
The <varname>perl</varname> attribute can then be removed, and the
|
|
|
|
builder becomes even shorter:
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
source $stdenv/setup
|
|
|
|
genericBuild</programlisting>
|
|
|
|
|
|
|
|
In fact, <varname>mkDerivation</varname> provides a default builder
|
|
|
|
that looks exactly like that, so it is actually possible to omit the
|
|
|
|
builder for Hello entirely.</para>
|
|
|
|
|
2014-12-14 00:39:32 +00:00
|
|
|
</section>
|