2014-08-24 18:18:18 +01: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-custom-packages">
|
2018-05-02 00:57:09 +01:00
|
|
|
|
<title>Adding Custom Packages</title>
|
2014-08-24 18:18:18 +01:00
|
|
|
|
|
2018-05-02 00:57:09 +01:00
|
|
|
|
<para>
|
2019-09-19 18:17:30 +01:00
|
|
|
|
It’s possible that a package you need is not available in NixOS. In that
|
|
|
|
|
case, you can do two things. First, you can clone the Nixpkgs repository, add
|
|
|
|
|
the package to your clone, and (optionally) submit a patch or pull request to
|
|
|
|
|
have it accepted into the main Nixpkgs repository. This is described in
|
|
|
|
|
detail in the <link
|
2020-04-18 21:51:19 +01:00
|
|
|
|
xlink:href="https://nixos.org/nixpkgs/manual">Nixpkgs
|
2019-09-19 18:17:30 +01:00
|
|
|
|
manual</link>. In short, you clone Nixpkgs:
|
2014-08-24 18:18:18 +01:00
|
|
|
|
<screen>
|
2019-06-17 12:25:50 +01:00
|
|
|
|
<prompt>$ </prompt>git clone https://github.com/NixOS/nixpkgs
|
|
|
|
|
<prompt>$ </prompt>cd nixpkgs
|
2014-08-24 18:18:18 +01:00
|
|
|
|
</screen>
|
2019-09-19 18:17:30 +01:00
|
|
|
|
Then you write and test the package as described in the Nixpkgs manual.
|
|
|
|
|
Finally, you add it to <literal>environment.systemPackages</literal>, e.g.
|
2014-08-24 18:18:18 +01:00
|
|
|
|
<programlisting>
|
2018-04-05 09:43:56 +01:00
|
|
|
|
<xref linkend="opt-environment.systemPackages"/> = [ pkgs.my-package ];
|
2014-08-24 18:18:18 +01:00
|
|
|
|
</programlisting>
|
2019-09-19 18:17:30 +01:00
|
|
|
|
and you run <command>nixos-rebuild</command>, specifying your own Nixpkgs
|
|
|
|
|
tree:
|
2014-08-24 18:18:18 +01:00
|
|
|
|
<screen>
|
2016-06-01 15:23:32 +01:00
|
|
|
|
# nixos-rebuild switch -I nixpkgs=/path/to/my/nixpkgs</screen>
|
2018-05-02 00:57:09 +01:00
|
|
|
|
</para>
|
2014-08-24 18:18:18 +01:00
|
|
|
|
|
2018-05-02 00:57:09 +01:00
|
|
|
|
<para>
|
2019-09-19 18:17:30 +01:00
|
|
|
|
The second possibility is to add the package outside of the Nixpkgs tree. For
|
|
|
|
|
instance, here is how you specify a build of the
|
|
|
|
|
<link xlink:href="https://www.gnu.org/software/hello/">GNU Hello</link>
|
|
|
|
|
package directly in <filename>configuration.nix</filename>:
|
2014-08-24 18:18:18 +01:00
|
|
|
|
<programlisting>
|
2018-04-05 09:43:56 +01:00
|
|
|
|
<xref linkend="opt-environment.systemPackages"/> =
|
2014-08-24 18:18:18 +01:00
|
|
|
|
let
|
|
|
|
|
my-hello = with pkgs; stdenv.mkDerivation rec {
|
|
|
|
|
name = "hello-2.8";
|
|
|
|
|
src = fetchurl {
|
|
|
|
|
url = "mirror://gnu/hello/${name}.tar.gz";
|
|
|
|
|
sha256 = "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
in
|
|
|
|
|
[ my-hello ];
|
|
|
|
|
</programlisting>
|
2019-09-19 18:17:30 +01:00
|
|
|
|
Of course, you can also move the definition of <literal>my-hello</literal>
|
|
|
|
|
into a separate Nix expression, e.g.
|
2014-08-24 18:18:18 +01:00
|
|
|
|
<programlisting>
|
2018-04-05 09:43:56 +01:00
|
|
|
|
<xref linkend="opt-environment.systemPackages"/> = [ (import ./my-hello.nix) ];
|
2014-08-24 18:18:18 +01:00
|
|
|
|
</programlisting>
|
2018-05-02 00:57:09 +01:00
|
|
|
|
where <filename>my-hello.nix</filename> contains:
|
2014-08-24 18:18:18 +01:00
|
|
|
|
<programlisting>
|
|
|
|
|
with import <nixpkgs> {}; # bring all of Nixpkgs into scope
|
|
|
|
|
|
|
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
|
name = "hello-2.8";
|
|
|
|
|
src = fetchurl {
|
|
|
|
|
url = "mirror://gnu/hello/${name}.tar.gz";
|
|
|
|
|
sha256 = "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6";
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
</programlisting>
|
2018-05-02 00:57:09 +01:00
|
|
|
|
This allows testing the package easily:
|
2014-08-24 18:18:18 +01:00
|
|
|
|
<screen>
|
2019-06-17 12:25:50 +01:00
|
|
|
|
<prompt>$ </prompt>nix-build my-hello.nix
|
|
|
|
|
<prompt>$ </prompt>./result/bin/hello
|
2014-08-24 18:18:18 +01:00
|
|
|
|
Hello, world!
|
|
|
|
|
</screen>
|
2018-05-02 00:57:09 +01:00
|
|
|
|
</para>
|
2014-08-24 18:18:18 +01:00
|
|
|
|
</section>
|