2008-06-17 15:19:59 +01:00
|
|
|
|
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
|
|
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
2009-09-25 12:15:50 +01:00
|
|
|
|
xml:id="chap-quick-start">
|
2018-05-02 00:54:21 +01:00
|
|
|
|
<title>Quick Start to Adding a Package</title>
|
|
|
|
|
<para>
|
|
|
|
|
To add a package to Nixpkgs:
|
|
|
|
|
<orderedlist>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
Checkout the Nixpkgs source tree:
|
2008-06-17 15:19:59 +01:00
|
|
|
|
<screen>
|
2019-06-17 12:25:50 +01:00
|
|
|
|
<prompt>$ </prompt>git clone https://github.com/NixOS/nixpkgs
|
|
|
|
|
<prompt>$ </prompt>cd nixpkgs</screen>
|
2008-06-17 15:19:59 +01:00
|
|
|
|
</para>
|
2018-05-02 00:54:21 +01:00
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
Find a good place in the Nixpkgs tree to add the Nix expression for your
|
|
|
|
|
package. For instance, a library package typically goes into
|
|
|
|
|
<filename>pkgs/development/libraries/<replaceable>pkgname</replaceable></filename>,
|
|
|
|
|
while a web browser goes into
|
|
|
|
|
<filename>pkgs/applications/networking/browsers/<replaceable>pkgname</replaceable></filename>.
|
|
|
|
|
See <xref linkend="sec-organisation" /> for some hints on the tree
|
|
|
|
|
organisation. Create a directory for your package, e.g.
|
2008-06-17 15:19:59 +01:00
|
|
|
|
<screen>
|
2019-06-17 12:25:50 +01:00
|
|
|
|
<prompt>$ </prompt>mkdir pkgs/development/libraries/libfoo</screen>
|
2008-06-17 15:19:59 +01:00
|
|
|
|
</para>
|
2018-05-02 00:54:21 +01:00
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
In the package directory, create a Nix expression — a piece of code that
|
|
|
|
|
describes how to build the package. In this case, it should be a
|
|
|
|
|
<emphasis>function</emphasis> that is called with the package dependencies
|
|
|
|
|
as arguments, and returns a build of the package in the Nix store. The
|
|
|
|
|
expression should usually be called <filename>default.nix</filename>.
|
2008-06-17 15:19:59 +01:00
|
|
|
|
<screen>
|
2019-06-17 12:25:50 +01:00
|
|
|
|
<prompt>$ </prompt>emacs pkgs/development/libraries/libfoo/default.nix
|
|
|
|
|
<prompt>$ </prompt>git add pkgs/development/libraries/libfoo/default.nix</screen>
|
2008-06-17 15:19:59 +01:00
|
|
|
|
</para>
|
2018-05-02 00:54:21 +01:00
|
|
|
|
<para>
|
|
|
|
|
You can have a look at the existing Nix expressions under
|
|
|
|
|
<filename>pkgs/</filename> to see how it’s done. Here are some good
|
|
|
|
|
ones:
|
|
|
|
|
<itemizedlist>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
GNU Hello:
|
|
|
|
|
<link
|
2015-09-22 19:23:23 +01:00
|
|
|
|
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/hello/default.nix"><filename>pkgs/applications/misc/hello/default.nix</filename></link>.
|
2018-05-02 00:54:21 +01:00
|
|
|
|
Trivial package, which specifies some <varname>meta</varname>
|
|
|
|
|
attributes which is good practice.
|
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
GNU cpio:
|
|
|
|
|
<link
|
2015-07-17 16:00:20 +01:00
|
|
|
|
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/archivers/cpio/default.nix"><filename>pkgs/tools/archivers/cpio/default.nix</filename></link>.
|
2018-05-02 00:54:21 +01:00
|
|
|
|
Also a simple package. The generic builder in <varname>stdenv</varname>
|
|
|
|
|
does everything for you. It has no dependencies beyond
|
|
|
|
|
<varname>stdenv</varname>.
|
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
GNU Multiple Precision arithmetic library (GMP):
|
|
|
|
|
<link
|
2014-04-14 07:12:01 +01:00
|
|
|
|
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/gmp/5.1.x.nix"><filename>pkgs/development/libraries/gmp/5.1.x.nix</filename></link>.
|
2018-05-02 00:54:21 +01:00
|
|
|
|
Also done by the generic builder, but has a dependency on
|
|
|
|
|
<varname>m4</varname>.
|
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
Pan, a GTK-based newsreader:
|
|
|
|
|
<link
|
2012-09-04 15:14:01 +01:00
|
|
|
|
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/networking/newsreaders/pan/default.nix"><filename>pkgs/applications/networking/newsreaders/pan/default.nix</filename></link>.
|
2018-05-02 00:54:21 +01:00
|
|
|
|
Has an optional dependency on <varname>gtkspell</varname>, which is
|
|
|
|
|
only built if <varname>spellCheck</varname> is <literal>true</literal>.
|
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
Apache HTTPD:
|
|
|
|
|
<link
|
2013-09-24 04:01:13 +01:00
|
|
|
|
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/servers/http/apache-httpd/2.4.nix"><filename>pkgs/servers/http/apache-httpd/2.4.nix</filename></link>.
|
2018-05-02 00:54:21 +01:00
|
|
|
|
A bunch of optional features, variable substitutions in the configure
|
|
|
|
|
flags, a post-install hook, and miscellaneous hackery.
|
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
Thunderbird:
|
|
|
|
|
<link
|
2013-09-24 04:01:13 +01:00
|
|
|
|
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/networking/mailreaders/thunderbird/default.nix"><filename>pkgs/applications/networking/mailreaders/thunderbird/default.nix</filename></link>.
|
2018-05-02 00:54:21 +01:00
|
|
|
|
Lots of dependencies.
|
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
JDiskReport, a Java utility:
|
|
|
|
|
<link
|
2012-09-04 15:14:01 +01:00
|
|
|
|
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/misc/jdiskreport/default.nix"><filename>pkgs/tools/misc/jdiskreport/default.nix</filename></link>
|
2018-05-02 00:54:21 +01:00
|
|
|
|
(and the
|
|
|
|
|
<link
|
2012-09-04 15:14:01 +01:00
|
|
|
|
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/misc/jdiskreport/builder.sh">builder</link>).
|
2018-05-02 00:54:21 +01:00
|
|
|
|
Nixpkgs doesn’t have a decent <varname>stdenv</varname> for Java yet
|
|
|
|
|
so this is pretty ad-hoc.
|
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
XML::Simple, a Perl module:
|
|
|
|
|
<link
|
2012-09-04 15:14:01 +01:00
|
|
|
|
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/perl-packages.nix"><filename>pkgs/top-level/perl-packages.nix</filename></link>
|
2018-05-02 00:54:21 +01:00
|
|
|
|
(search for the <varname>XMLSimple</varname> attribute). Most Perl
|
|
|
|
|
modules are so simple to build that they are defined directly in
|
|
|
|
|
<filename>perl-packages.nix</filename>; no need to make a separate file
|
|
|
|
|
for them.
|
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
Adobe Reader:
|
|
|
|
|
<link
|
2012-09-04 15:14:01 +01:00
|
|
|
|
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/adobe-reader/default.nix"><filename>pkgs/applications/misc/adobe-reader/default.nix</filename></link>.
|
2018-05-02 00:54:21 +01:00
|
|
|
|
Shows how binary-only packages can be supported. In particular the
|
|
|
|
|
<link
|
2012-09-04 15:14:01 +01:00
|
|
|
|
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/adobe-reader/builder.sh">builder</link>
|
2018-05-02 00:54:21 +01:00
|
|
|
|
uses <command>patchelf</command> to set the RUNPATH and ELF interpreter
|
|
|
|
|
of the executables so that the right libraries are found at runtime.
|
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
</itemizedlist>
|
2008-06-17 15:19:59 +01:00
|
|
|
|
</para>
|
2018-05-02 00:54:21 +01:00
|
|
|
|
<para>
|
|
|
|
|
Some notes:
|
|
|
|
|
<itemizedlist>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
All <varname linkend="chap-meta">meta</varname> attributes are
|
|
|
|
|
optional, but it’s still a good idea to provide at least the
|
|
|
|
|
<varname>description</varname>, <varname>homepage</varname> and
|
|
|
|
|
<varname
|
|
|
|
|
linkend="sec-meta-license">license</varname>.
|
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
2018-11-05 19:16:51 +00:00
|
|
|
|
You can use <command>nix-prefetch-url</command>
|
2019-03-09 05:07:11 +00:00
|
|
|
|
<replaceable>url</replaceable> to get the SHA-256 hash of source
|
|
|
|
|
distributions. There are similar commands as
|
2018-05-02 00:54:21 +01:00
|
|
|
|
<command>nix-prefetch-git</command> and
|
|
|
|
|
<command>nix-prefetch-hg</command> available in
|
|
|
|
|
<literal>nix-prefetch-scripts</literal> package.
|
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
A list of schemes for <literal>mirror://</literal> URLs can be found in
|
|
|
|
|
<link
|
|
|
|
|
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/fetchurl/mirrors.nix"><filename>pkgs/build-support/fetchurl/mirrors.nix</filename></link>.
|
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
</itemizedlist>
|
2008-06-17 15:19:59 +01:00
|
|
|
|
</para>
|
2018-05-02 00:54:21 +01:00
|
|
|
|
<para>
|
|
|
|
|
The exact syntax and semantics of the Nix expression language, including
|
|
|
|
|
the built-in function, are described in the Nix manual in the
|
|
|
|
|
<link
|
2012-10-18 15:10:36 +01:00
|
|
|
|
xlink:href="http://hydra.nixos.org/job/nix/trunk/tarball/latest/download-by-type/doc/manual/#chap-writing-nix-expressions">chapter
|
2018-05-02 00:54:21 +01:00
|
|
|
|
on writing Nix expressions</link>.
|
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
Add a call to the function defined in the previous step to
|
|
|
|
|
<link
|
2012-09-04 15:14:01 +01:00
|
|
|
|
xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/all-packages.nix"><filename>pkgs/top-level/all-packages.nix</filename></link>
|
2018-05-02 00:54:21 +01:00
|
|
|
|
with some descriptive name for the variable, e.g.
|
|
|
|
|
<varname>libfoo</varname>.
|
|
|
|
|
<screen>
|
2019-06-17 12:25:50 +01:00
|
|
|
|
<prompt>$ </prompt>emacs pkgs/top-level/all-packages.nix</screen>
|
2008-06-17 15:19:59 +01:00
|
|
|
|
</para>
|
2018-05-02 00:54:21 +01:00
|
|
|
|
<para>
|
|
|
|
|
The attributes in that file are sorted by category (like “Development /
|
|
|
|
|
Libraries”) that more-or-less correspond to the directory structure of
|
|
|
|
|
Nixpkgs, and then by attribute name.
|
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
To test whether the package builds, run the following command from the
|
|
|
|
|
root of the nixpkgs source tree:
|
|
|
|
|
<screen>
|
2019-06-17 12:25:50 +01:00
|
|
|
|
<prompt>$ </prompt>nix-build -A libfoo</screen>
|
2018-05-02 00:54:21 +01:00
|
|
|
|
where <varname>libfoo</varname> should be the variable name defined in the
|
|
|
|
|
previous step. You may want to add the flag <option>-K</option> to keep
|
|
|
|
|
the temporary build directory in case something fails. If the build
|
|
|
|
|
succeeds, a symlink <filename>./result</filename> to the package in the
|
|
|
|
|
Nix store is created.
|
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
|
|
|
|
If you want to install the package into your profile (optional), do
|
|
|
|
|
<screen>
|
2019-06-17 12:25:50 +01:00
|
|
|
|
<prompt>$ </prompt>nix-env -f . -iA libfoo</screen>
|
2008-06-17 15:19:59 +01:00
|
|
|
|
</para>
|
2018-05-02 00:54:21 +01:00
|
|
|
|
</listitem>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>
|
2019-08-06 02:53:07 +01:00
|
|
|
|
Optionally commit the new package and open a pull request
|
|
|
|
|
<link
|
|
|
|
|
xlink:href="https://github.com/NixOS/nixpkgs/pulls">to
|
|
|
|
|
nixpkgs</link>, or use
|
|
|
|
|
<link
|
2019-08-17 07:13:23 +01:00
|
|
|
|
xlink:href="https://discourse.nixos.org/t/about-the-patches-category/477">
|
|
|
|
|
the Patches category</link> on Discourse for sending a patch without a
|
|
|
|
|
GitHub account.
|
2018-05-02 00:54:21 +01:00
|
|
|
|
</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
</orderedlist>
|
|
|
|
|
</para>
|
2009-09-25 12:15:50 +01:00
|
|
|
|
</chapter>
|