2016-12-17 19:05:21 +01:00
|
|
|
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
|
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
|
|
xml:id="chap-overlays">
|
|
|
|
|
|
|
|
<title>Overlays</title>
|
|
|
|
|
2017-01-15 16:07:29 +01:00
|
|
|
<para>This chapter describes how to extend and change Nixpkgs packages using
|
|
|
|
overlays. Overlays are used to add layers in the fix-point used by Nixpkgs
|
|
|
|
to compose the set of all packages.</para>
|
2016-12-17 19:05:21 +01:00
|
|
|
|
2017-08-09 20:00:30 +02:00
|
|
|
<para>Nixpkgs can be configured with a list of overlays, which are
|
|
|
|
applied in order. This means that the order of the overlays can be significant
|
|
|
|
if multiple layers override the same package.</para>
|
|
|
|
|
2016-12-17 19:05:21 +01:00
|
|
|
<!--============================================================-->
|
|
|
|
|
|
|
|
<section xml:id="sec-overlays-install">
|
2017-08-09 20:00:30 +02:00
|
|
|
<title>Installing overlays</title>
|
2016-12-17 19:05:21 +01:00
|
|
|
|
2017-08-09 20:00:30 +02:00
|
|
|
<para>The list of overlays is determined as follows:
|
2016-12-17 19:05:21 +01:00
|
|
|
|
|
|
|
<orderedlist>
|
|
|
|
|
|
|
|
<listitem>
|
2017-08-09 20:00:30 +02:00
|
|
|
<para>First, if an <varname>overlays</varname> argument to the nixpkgs function itself is given,
|
|
|
|
then that is used. This can be passed explicitly when importing nipxkgs, for example
|
|
|
|
<literal>import <nixpkgs> { overlays = [ overlay1 overlay2 ] }</literal>.</para>
|
2016-12-17 19:05:21 +01:00
|
|
|
|
2017-08-09 20:00:30 +02:00
|
|
|
<para>On a NixOS system the value of the <literal>nixpkgs.overlays</literal> option, if present,
|
|
|
|
is passed to the system Nixpkgs in this way. Note that this does not affect the overlays for
|
|
|
|
non-NixOS operations (e.g. <literal>nix-env</literal>), which are looked up independently.</para>
|
2016-12-17 19:05:21 +01:00
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
2017-08-09 20:00:30 +02:00
|
|
|
<para>Otherwise, if the Nix path entry <literal><nixpkgs-overlays></literal> exists and is a
|
|
|
|
directory, then the result is the set of overlays found in that directory, ordered lexicographically.</para>
|
2016-12-17 19:05:21 +01:00
|
|
|
|
2017-08-09 20:00:30 +02:00
|
|
|
<para>See the section on <literal>NIX_PATH</literal> in the Nix manual for more details on how to
|
|
|
|
set a value for <literal><nixpkgs-overlays>.</literal></para>
|
2016-12-17 19:05:21 +01:00
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
2017-08-09 20:00:30 +02:00
|
|
|
<para>Otherwise, if <filename>~/.config/nixpkgs/overlays/</filename> exists and is a directory, then
|
|
|
|
the result is the set of overlays found in that directory, ordered lexicographically.</para>
|
2016-12-17 19:05:21 +01:00
|
|
|
</listitem>
|
|
|
|
|
|
|
|
</orderedlist>
|
|
|
|
</para>
|
|
|
|
|
2017-08-13 15:42:33 +02:00
|
|
|
<para>For the second and third options, overlays are extracted from the given directory as files,
|
2017-08-09 20:00:30 +02:00
|
|
|
directories containing a <filename>default.nix</filename>, or symlinks to one of those.</para>
|
2016-12-17 19:05:21 +01:00
|
|
|
|
2017-08-09 20:00:30 +02:00
|
|
|
<para>The last option provides a convenient way to install an overlay from a repository,
|
|
|
|
by cloning the overlay's repository and adding a symbolic link to it in
|
|
|
|
<filename>~/.config/nixpkgs/overlays/</filename>.</para>
|
2016-12-17 19:05:21 +01:00
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<!--============================================================-->
|
|
|
|
|
2017-08-09 20:00:30 +02:00
|
|
|
<section xml:id="sec-overlays-definition">
|
|
|
|
<title>Defining overlays</title>
|
2016-12-17 19:05:21 +01:00
|
|
|
|
2017-08-09 20:00:30 +02:00
|
|
|
<para>Overlays are Nix functions which accept two arguments,
|
|
|
|
conventionally called <varname>self</varname> and <varname>super</varname>,
|
|
|
|
and return a set of packages. For example, the following is a valid overlay.</para>
|
2016-12-17 19:05:21 +01:00
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
self: super:
|
|
|
|
|
|
|
|
{
|
2017-01-15 16:07:29 +01:00
|
|
|
boost = super.boost.override {
|
|
|
|
python = self.python3;
|
|
|
|
};
|
|
|
|
rr = super.callPackage ./pkgs/rr {
|
|
|
|
stdenv = self.stdenv_32bit;
|
2016-12-17 19:05:21 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
</programlisting>
|
|
|
|
|
2017-08-09 20:00:30 +02:00
|
|
|
<para>The first argument (<varname>self</varname>) corresponds to the final package
|
2017-01-15 16:07:29 +01:00
|
|
|
set. You should use this set for the dependencies of all packages specified in your
|
|
|
|
overlay. For example, all the dependencies of <varname>rr</varname> in the example above come
|
2017-06-11 22:12:59 +02:00
|
|
|
from <varname>self</varname>, as well as the overridden dependencies used in the
|
2017-01-15 16:07:29 +01:00
|
|
|
<varname>boost</varname> override.</para>
|
2016-12-17 19:05:21 +01:00
|
|
|
|
2017-08-09 20:00:30 +02:00
|
|
|
<para>The second argument (<varname>super</varname>)
|
2016-12-17 19:05:21 +01:00
|
|
|
corresponds to the result of the evaluation of the previous stages of
|
2017-01-15 16:07:29 +01:00
|
|
|
Nixpkgs. It does not contain any of the packages added by the current
|
2017-08-09 20:00:30 +02:00
|
|
|
overlay, nor any of the following overlays. This set should be used either
|
2017-01-15 16:07:29 +01:00
|
|
|
to refer to packages you wish to override, or to access functions defined
|
|
|
|
in Nixpkgs. For example, the original recipe of <varname>boost</varname>
|
|
|
|
in the above example, comes from <varname>super</varname>, as well as the
|
|
|
|
<varname>callPackage</varname> function.</para>
|
2016-12-17 19:05:21 +01:00
|
|
|
|
|
|
|
<para>The value returned by this function should be a set similar to
|
2017-08-09 20:00:30 +02:00
|
|
|
<filename>pkgs/top-level/all-packages.nix</filename>, containing
|
2017-01-15 16:07:29 +01:00
|
|
|
overridden and/or new packages.</para>
|
2016-12-17 19:05:21 +01:00
|
|
|
|
2017-08-09 20:00:30 +02:00
|
|
|
<para>Overlays are similar to other methods for customizing Nixpkgs, in particular
|
|
|
|
the <literal>packageOverrides</literal> attribute described in <xref linkend="sec-modify-via-packageOverrides"/>.
|
|
|
|
Indeed, <literal>packageOverrides</literal> acts as an overlay with only the
|
|
|
|
<varname>super</varname> argument. It is therefore appropriate for basic use,
|
|
|
|
but overlays are more powerful and easier to distribute.</para>
|
|
|
|
|
2016-12-17 19:05:21 +01:00
|
|
|
</section>
|
|
|
|
|
|
|
|
</chapter>
|