doc: Write "Adding More Jobs".
[?]
Oct 12, 2011, 2:54 PM
LW755CJKCIPO7NR7D5TP5WZNGCP5UWLBMA7KJXMHJEB6XIJJGO3QCDependencies
- [2]
EE53ECTSdoc: Write "Building from the Command Line". - [*]
PKE6I67Sdoc: Import the "Creating Projects" chapter by Visser & Dolstra.
Change contents
- edit in doc/manual/projects.xml at line 416[2.2121][4.5239]
</section><section><title>Adding More Jobs</title><para><xref linkend='ex-hello' /> illustrates how to write the mostbasic jobs, <varname>tarball</varname> and<varname>build</varname>. In practice, much more can be done byusing features readily provided by Nixpkgs or by creating new jobsas customizations of existing jobs.</para><para>For instance, test coverage report for projects compiled with GCCcan be automatically generated using the<varname>coverageAnalysis</varname> function provided by Nixpkgsinstead of <varname>nixBuild</varname>. Back to our GNU Helloexample, we can define a <varname>coverage</varname> job thatproduces an HTML code coverage report directly readable from thecorresponding Hydra build page:<programlisting>coverage ={ tarball ? jobs.tarball {}, system ? builtins.currentSystem}:let pkgs = import nixpkgs { inherit system; }; inpkgs.releaseTools.coverageAnalysis {name = "hello" ;src = tarball;configureFlags = [ "--disable-silent-rules" ];}; </programlisting>As can be seen, the only difference compared to<varname>build</varname> is the use of<varname>coverageAnalysis</varname>.</para><para>Nixpkgs provides many more build tools, including the ability torun build in virtual machines, which can themselves run anotherGNU/Linux distribution, which allows for the creation of packagesfor these distributions. Please see <linkxlink:href="https://svn.nixos.org/repos/nix/nixpkgs/trunk/pkgs/build-support/release/">the<filename>pkgs/build-support/release</filename> directory</link>of Nixpkgs for more. The NixOS manual also contains informationabout whole-system testing in virtual machine.</para><para>Now, assume we want to build Hello with an old version of GCC, andwith different <command>configure</command> flags. A new<varname>build_exotic</varname> job can be written that simply<emphasis>overrides</emphasis> the relevant arguments passed to<varname>nixBuild</varname>: - edit in doc/manual/projects.xml at line 474[4.5240][4.5240]
<programlisting>build_exotic ={ tarball ? jobs.tarball {}, system ? builtins.currentSystem}:letpkgs = import nixpkgs { inherit system; };build = jobs.build { inherit tarball system; };inpkgs.lib.overrideDerivation build (attrs: {buildInputs = [ pkgs.gcc33 ];preConfigure = "gcc --version";configureFlags =attrs.configureFlags ++ [ "--disable-nls" ];}); </programlisting>The <varname>build_exotic</varname> job reuses<varname>build</varname> and overrides some of its arguments: itadds a dependency on GCC 3.3, a pre-configure phase that runs<command>gcc --version</command>, and adds the<literal>--disable-nls</literal> configure flags.</para><para>This customization mechanism is very powerful. For instance, itcan be used to change the way Hello and <emphasis>all</emphasis>its dependencies–including the C library and compiler used tobuild it–are built. See the Nixpkgs manual for more.</para> - edit in doc/manual/projects.xml at line 506[4.5253][4.5253]