at 17.09-beta 2.4 kB view raw
1<section xmlns="http://docbook.org/ns/docbook" 2 xmlns:xlink="http://www.w3.org/1999/xlink" 3 xmlns:xi="http://www.w3.org/2001/XInclude" 4 version="5.0" 5 xml:id="sec-custom-packages"> 6 7<title>Adding Custom Packages</title> 8 9<para>It’s possible that a package you need is not available in NixOS. 10In that case, you can do two things. First, you can clone the Nixpkgs 11repository, add the package to your clone, and (optionally) submit a 12patch or pull request to have it accepted into the main Nixpkgs 13repository. This is described in detail in the <link 14xlink:href="http://nixos.org/nixpkgs/manual">Nixpkgs manual</link>. 15In short, you clone Nixpkgs: 16 17<screen> 18$ git clone git://github.com/NixOS/nixpkgs.git 19$ cd nixpkgs 20</screen> 21 22Then you write and test the package as described in the Nixpkgs 23manual. Finally, you add it to 24<literal>environment.systemPackages</literal>, e.g. 25 26<programlisting> 27environment.systemPackages = [ pkgs.my-package ]; 28</programlisting> 29 30and you run <command>nixos-rebuild</command>, specifying your own 31Nixpkgs tree: 32 33<screen> 34# nixos-rebuild switch -I nixpkgs=/path/to/my/nixpkgs</screen> 35 36</para> 37 38<para>The second possibility is to add the package outside of the 39Nixpkgs tree. For instance, here is how you specify a build of the 40<link xlink:href="http://www.gnu.org/software/hello/">GNU Hello</link> 41package directly in <filename>configuration.nix</filename>: 42 43<programlisting> 44environment.systemPackages = 45 let 46 my-hello = with pkgs; stdenv.mkDerivation rec { 47 name = "hello-2.8"; 48 src = fetchurl { 49 url = "mirror://gnu/hello/${name}.tar.gz"; 50 sha256 = "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"; 51 }; 52 }; 53 in 54 [ my-hello ]; 55</programlisting> 56 57Of course, you can also move the definition of 58<literal>my-hello</literal> into a separate Nix expression, e.g. 59<programlisting> 60environment.systemPackages = [ (import ./my-hello.nix) ]; 61</programlisting> 62where <filename>my-hello.nix</filename> contains: 63<programlisting> 64with import &lt;nixpkgs> {}; # bring all of Nixpkgs into scope 65 66stdenv.mkDerivation rec { 67 name = "hello-2.8"; 68 src = fetchurl { 69 url = "mirror://gnu/hello/${name}.tar.gz"; 70 sha256 = "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"; 71 }; 72} 73</programlisting> 74 75This allows testing the package easily: 76<screen> 77$ nix-build my-hello.nix 78$ ./result/bin/hello 79Hello, world! 80</screen> 81 82</para> 83 84</section>