doc: Add preliminary section about `release.nix'.
[?]
Oct 11, 2011, 9:05 PM
2LTNY56W6QEDRSI6IWRZGQPTJTAFQSGIQO6FBTU7M4VQCTF6OVNACDependencies
- [2]
PKE6I67Sdoc: Import the "Creating Projects" chapter by Visser & Dolstra.
Change contents
- replacement in doc/manual/projects.xml at line 153
<title><filename>release.nix</filename></title><title>Build Recipes</title><para>Build jobs and <emphasis>build recipes</emphasis> for a jobset arespecified in a text file written in the <linkxlink:href="http://nixos.org/nix/">Nix language</link>. Therecipe is actually called a <emphasis>Nix expression</emphasis> inNix parlance. By convention this file is often called<filename>release.nix</filename>.</para> - replacement in doc/manual/projects.xml at line 164
- Voorbeelden van Nix expressies voor Hydra:<para>The <filename>release.nix</filename> file is typically kept underversion control, and the repository that contains it one of thebuild inputs of the corresponding–often called<literal>hydraConfig</literal> by convention. The repository forthat file and the actual file name are specified on the webinterface of Hydra under the <literal>Setup</literal> tab of thejobset's overview page, under the <literal>Nixexpression</literal> heading. See, for example, the <linkxlink:href="http://hydra.nixos.org/jobset/patchelf/trunk">jobsetoverview page</link> of the PatchELF project, and <linkxlink:href="https://svn.nixos.org/repos/nix/patchelf/trunk/release.nix">the corresponding Nix file</link>.</para> - edit in doc/manual/projects.xml at line 179
<para>Knowledge of the Nix language is recommended, but the examplebelow should already give a good idea of how it works:</para> - edit in doc/manual/projects.xml at line 184
<example xml:id='ex-hello'><title><filename>release.nix</filename> file for GNU Hello</title><programlisting>{ nixpkgs }: <co xml:id='ex-hello-co-nixpkgs' />letpkgs = import nixpkgs {}; <co xml:id='ex-hello-co-import-nixpkgs' /> - replacement in doc/manual/projects.xml at line 192
https://svn.nixos.org/repos/nix/patchelf/trunk/release.nixhttps://svn.nixos.org/repos/nix/nix/trunk/release.nixhttps://svn.nixos.org/repos/nix/hydra/trunk/release.nixjobs = rec { <co xml:id='ex-hello-co-jobs' />tarball = <co xml:id='ex-hello-co-tarball' />{ helloSrc }: <co xml:id='ex-hello-co-tarball-arg' />pkgs.releaseTools.sourceTarball { <co xml:id='ex-hello-co-source-tarball' />name = "hello-tarball";src = helloSrc;buildInputs = (with pkgs; [ gettext texLive texinfo ]);};build = <co xml:id='ex-hello-co-build' />{ tarball ? jobs.tarball {} <co xml:id='ex-hello-co-build-args' />, system ? builtins.currentSystem}:let pkgs = import nixpkgs { inherit system; }; inpkgs.releaseTools.nixBuild { <co xml:id='ex-hello-co-nix-build' />name = "hello" ;src = tarball;};};injobs <co xml:id='ex-hello-body' /></programlisting></example><para><xref linkend='ex-hello' /> shows what a<filename>release.nix</filename> file for <linkxlink:href="http://www.gnu.org/software/hello/">GNU Hello</link>would you like. GNU Hello is representative of many GNUand non-GNU free software projects:<itemizedlist><listitem>it uses the GNU Build System, namely GNU Autoconf,and GNU Automake; for users, it means it can be installedusing the <linkxlink:href="http://www.gnu.org/prep/standards/html_node/Managing-Releases.html">usual<literal>./configure && make install</literal>procedure</link>;</listitem><listitem>it uses Gettext for internationalization;</listitem><listitem>it has a Texinfo manual, which can be rendered as PDFwith TeX.</listitem></itemizedlist>The file defines a jobset consisting of two jobs:<literal>tarball</literal>, and <literal>build</literal>. Itcontains the following elements (referenced from the figure bynumbers):<calloutlist><callout arearefs='ex-hello-co-nixpkgs'><para>This specifies a function of one named arguments,<varname>nixpkgs</varname>. This function and thosedefined below is called by Hydra. Here the<varname>nixpkgs</varname> argument is meant to be acheckout of the <linkxlink:href="http://nixos.org/nixpkgs/">Nixpkgs</link>software distribution.</para><para>Hydra inspects the formal argument list of the function(here, the <varname>nixpkgs</varname> argument) and passesit the corresponding parameter specified as a build inputon Hydra's web interface. In this case, the web interfaceshould show a <varname>nixpkgs</varname> build input,which is a checkout of the Nixpkgs source code repository.</para></callout><callout arearefs='ex-hello-co-import-nixpkgs'><para>This defines a variable <varname>pkgs</varname> holdingthe set of packages provided by Nixpkgs.</para></callout><callout arearefs='ex-hello-co-jobs'><para>This defines a variable holding the two Hydrajobs–an <emphasis>attribute set</emphasis> in Nix.</para></callout><callout arearefs='ex-hello-co-tarball'><para>This is the definition of the first job, named<varname>tarball</varname>. The purpose of this job is toproduce a usable source code tarball.</para></callout><callout arearefs='ex-hello-co-tarball-args'><para>The <varname>tarball</varname> takes an additionalargument called <varname>helloSrc</varname>. Again, thisargument is passed by Hydra and is meant to be a checkoutof GNU Hello's source code repository.</para></callout><callout arearefs='ex-hello-co-source-tarball'><para>The <varname>tarball</varname> job calls the<varname>sourceTarball</varname> function, which (roughly)runs <command>autoreconf && ./configure &&make dist</command> on the checkout. The<varname>buildInputs</varname> attribute specifiesadditional software dependencies for the job.</para></callout><callout arearefs='ex-hello-co-build'><para>This is the definition of the <varname>build</varname>job, whose purpose is to build Hello from the tarballproduced above.</para></callout><callout arearefs='ex-hello-co-build-args'><para>The <varname>build</varname> function takes two additionalparameter: <varname>tarball</varname>, which is meant tobe the result of the <varname>tarball</varname> job, and<varname>system</varname>, which should be a stringdefining the Nix system type–e.g.,<literal>"x86_64-linux"</literal>.</para><para>Again, these parameters are passed by Hydra when it calls<varname>build</varname>. Thus, they must be defined asbuild inputs in Hydra: <varname>tarball</varname> shouldhave type <literal>Build Output</literal>, its value beingthe latest output of the <varname>tarball</varname> job,and <varname>system</varname> should be a string.</para><para>The question mark after <literal>tarball</literal> and<literal>system</literal> defines default values for thesearguments, and is only useful for debugging.</para></callout><callout arearefs='ex-hello-co-nix-build'><para>The <varname>build</varname> job calls the<varname>nixBuild</varname> function, which unpacks thetarball, then runs <command>./configure && make&& make check && make install</command>.</para></callout><callout arearefs='ex-hello-co-body'><para>Finally, the set of jobs is returned to Hydra, as a Nixattribute set.</para></callout></calloutlist></para>