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