1 <chapter xmlns="http://docbook.org/ns/docbook"
2 xmlns:xlink="http://www.w3.org/1999/xlink"
3 xml:id="chap-quick-start">
5 <title>Quick Start to Adding a Package</title>
7 <para>To add a package to Nixpkgs:
12 <para>Checkout the Nixpkgs source tree:
15 $ svn checkout https://svn.nixos.org/repos/nix/nixpkgs/trunk nixpkgs
22 <para>Find a good place in the Nixpkgs tree to add the Nix
23 expression for your package. For instance, a library package
25 <filename>pkgs/development/libraries/<replaceable>pkgname</replaceable></filename>,
26 while a web browser goes into
27 <filename>pkgs/applications/networking/browsers/<replaceable>pkgname</replaceable></filename>.
28 See <xref linkend="sec-organisation" /> for some hints on the tree
29 organisation. Create a directory for your package, e.g.
32 $ svn mkdir pkgs/development/libraries/libfoo</screen>
38 <para>In the package directory, create a Nix expression — a piece
39 of code that describes how to build the package. In this case, it
40 should be a <emphasis>function</emphasis> that is called with the
41 package dependencies as arguments, and returns a build of the
42 package in the Nix store. The expression should usually be called
43 <filename>default.nix</filename>.
46 $ emacs pkgs/development/libraries/libfoo/default.nix
47 $ svn add pkgs/development/libraries/libfoo/default.nix</screen>
51 <para>You can have a look at the existing Nix expressions under
52 <filename>pkgs/</filename> to see how it’s done. Here are some
59 xlink:href="https://svn.nixos.org/repos/nix/nixpkgs/trunk/pkgs/tools/archivers/cpio/default.nix"><filename>pkgs/tools/archivers/cpio/default.nix</filename></link>.
60 The simplest possible package. The generic builder in
61 <varname>stdenv</varname> does everything for you. It has
62 no dependencies beyond <varname>stdenv</varname>.</para>
66 <para>GNU Hello: <link
67 xlink:href="https://svn.nixos.org/repos/nix/nixpkgs/trunk/pkgs/applications/misc/hello/ex-2/default.nix"><filename>pkgs/applications/misc/hello/ex-2/default.nix</filename></link>.
68 Also trivial, but it specifies some <varname>meta</varname>
69 attributes which is good practice.</para>
73 <para>GNU Multiple Precision arithmetic library (GMP): <link
74 xlink:href="https://svn.nixos.org/repos/nix/nixpkgs/trunk/pkgs/development/libraries/gmp/default.nix"><filename>pkgs/development/libraries/gmp/default.nix</filename></link>.
75 Also done by the generic builder, but has a dependency on
76 <varname>m4</varname>.</para>
80 <para>Pan, a GTK-based newsreader: <link
81 xlink:href="https://svn.nixos.org/repos/nix/nixpkgs/trunk/pkgs/applications/networking/newsreaders/pan/default.nix"><filename>pkgs/applications/networking/newsreaders/pan/default.nix</filename></link>.
82 Has an optional dependency on <varname>gtkspell</varname>,
83 which is only built if <varname>spellCheck</varname> is
84 <literal>true</literal>.</para>
88 <para>Apache HTTPD: <link
89 xlink:href="https://svn.nixos.org/repos/nix/nixpkgs/trunk/pkgs/servers/http/apache-httpd/default.nix"><filename>pkgs/servers/http/apache-httpd/default.nix</filename></link>.
90 A bunch of optional features, variable substitutions in the
91 configure flags, a post-install hook, and miscellaneous
96 <para>BitTorrent (wxPython-based): <link
97 xlink:href="https://svn.nixos.org/repos/nix/nixpkgs/trunk/pkgs/tools/networking/p2p/bittorrent/default.nix"><filename>pkgs/tools/networking/p2p/bittorrent/default.nix</filename></link>.
98 Uses an external <link
99 xlink:href="https://svn.nixos.org/repos/nix/nixpkgs/trunk/pkgs/tools/networking/p2p/bittorrent/builder.sh">build
100 script</link>, which can be useful if you have lots of code
101 that you don’t want cluttering up the Nix expression. But
102 external builders are mostly obsolete.
107 <para>Thunderbird: <link
108 xlink:href="https://svn.nixos.org/repos/nix/nixpkgs/trunk/pkgs/applications/networking/mailreaders/thunderbird-2.x/default.nix"><filename>pkgs/applications/networking/mailreaders/thunderbird-2.x/default.nix</filename></link>.
109 Lots of dependencies.</para>
113 <para>JDiskReport, a Java utility: <link
114 xlink:href="https://svn.nixos.org/repos/nix/nixpkgs/trunk/pkgs/tools/misc/jdiskreport/default.nix"><filename>pkgs/tools/misc/jdiskreport/default.nix</filename></link>
116 xlink:href="https://svn.nixos.org/repos/nix/nixpkgs/trunk/pkgs/tools/misc/jdiskreport/builder.sh">builder</link>).
117 Nixpkgs doesn’t have a decent <varname>stdenv</varname> for
118 Java yet so this is pretty ad-hoc.</para>
122 <para>XML::Simple, a Perl module: <link
123 xlink:href="https://svn.nixos.org/repos/nix/nixpkgs/trunk/pkgs/top-level/perl-packages.nix"><filename>pkgs/top-level/perl-packages.nix</filename></link>
124 (search for the <varname>XMLSimple</varname> attribute).
125 Most Perl modules are so simple to build that they are
126 defined directly in <filename>perl-packages.nix</filename>;
127 no need to make a separate file for them.</para>
131 <para>Adobe Reader: <link
132 xlink:href="https://svn.nixos.org/repos/nix/nixpkgs/trunk/pkgs/applications/misc/adobe-reader/default.nix"><filename>pkgs/applications/misc/adobe-reader/default.nix</filename></link>.
133 Shows how binary-only packages can be supported. In
135 xlink:href="https://svn.nixos.org/repos/nix/nixpkgs/trunk/pkgs/applications/misc/adobe-reader/builder.sh">builder</link>
136 uses <command>patchelf</command> to set the RUNPATH and ELF
137 interpreter of the executables so that the right libraries
138 are found at runtime.</para>
150 <para>All <varname linkend="chap-meta">meta</varname>
151 attributes are optional, but it’s still a good idea to
152 provide at least the <varname>description</varname>,
153 <varname>homepage</varname> and <varname
154 linkend="sec-meta-license">license</varname>.</para>
158 <para>You can use <command>nix-prefetch-url</command>
159 <replaceable>url</replaceable> to get the SHA-256 hash of
160 source distributions.</para>
164 <para>A list of schemes for <literal>mirror://</literal>
165 URLs can be found in <link
166 xlink:href="https://svn.nixos.org/repos/nix/nixpkgs/trunk/pkgs/build-support/fetchurl/mirrors.nix"><filename>pkgs/build-support/fetchurl/mirrors.nix</filename></link>.</para>
173 <para>The exact syntax and semantics of the Nix expression
174 language, including the built-in function, are described in the
175 Nix manual in the <link
176 xlink:href="http://nixos.org/releases/nix/unstable/manual/#chap-writing-nix-expressions">chapter
177 on writing Nix expressions</link>.</para>
182 <para>Add a call to the function defined in the previous step to
184 xlink:href="https://svn.nixos.org/repos/nix/nixpkgs/trunk/pkgs/top-level/all-packages.nix"><filename>pkgs/top-level/all-packages.nix</filename></link>
185 with some descriptive name for the variable,
186 e.g. <varname>libfoo</varname>.
189 $ emacs pkgs/top-level/all-packages.nix</screen>
193 <para>The attributes in that file are sorted by category (like
194 “Development / Libraries”) that more-or-less correspond to the
195 directory structure of Nixpkgs, and then by attribute name.</para>
199 <para>Test whether the package builds:
202 $ nix-build -A libfoo</screen>
204 where <varname>libfoo</varname> should be the variable name
205 defined in the previous step. You may want to add the flag
206 <option>-K</option> to keep the temporary build directory in case
207 something fails. If the build succeeds, a symlink
208 <filename>./result</filename> to the package in the Nix store is
213 <para>If you want to install the package into your profile
217 $ nix-env -f . -iA libfoo</screen>
223 <para>Optionally commit the new package (<command>svn
224 ci</command>) or send a patch to
225 <literal>nix-dev@cs.uu.nl</literal>.</para>
229 <para>If you want the TU Delft build farm to build binaries of the
230 package and make them available in the <link
231 xlink:href="http://nixos.org/releases/nixpkgs/channels/nixpkgs-unstable/"><literal>nixpkgs</literal>
232 channel</link>, add it to <link
233 xlink:href="https://svn.nixos.org/repos/nix/nixpkgs/trunk/pkgs/top-level/release.nix"><filename>pkgs/top-level/release.nix</filename></link>.</para>