···88overlays. Overlays are used to add layers in the fix-point used by Nixpkgs
99to compose the set of all packages.</para>
10101111+<para>Nixpkgs can be configured with a list of overlays, which are
1212+applied in order. This means that the order of the overlays can be significant
1313+if multiple layers override the same package.</para>
1414+1115<!--============================================================-->
12161317<section xml:id="sec-overlays-install">
1414-<title>Installing Overlays</title>
1818+<title>Installing overlays</title>
15191616-<para>The set of overlays is looked for in the following places. The
1717-first one present is considered, and all the rest are ignored:
2020+<para>The list of overlays is determined as follows:
18211922<orderedlist>
20232124 <listitem>
2222-2323- <para>As an argument of the imported attribute set. When importing Nixpkgs,
2424- the <varname>overlays</varname> attribute argument can be set to a list of
2525- functions, which is described in <xref linkend="sec-overlays-layout"/>.</para>
2525+ <para>First, if an <varname>overlays</varname> argument to the nixpkgs function itself is given,
2626+ then that is used. This can be passed explicitly when importing nipxkgs, for example
2727+ <literal>import <nixpkgs> { overlays = [ overlay1 overlay2 ] }</literal>.</para>
26282929+ <para>On a NixOS system the value of the <literal>nixpkgs.overlays</literal> option, if present,
3030+ is passed to the system Nixpkgs in this way. Note that this does not affect the overlays for
3131+ non-NixOS operations (e.g. <literal>nix-env</literal>), which are looked up independently.</para>
2732 </listitem>
28332934 <listitem>
3535+ <para>Otherwise, if the Nix path entry <literal><nixpkgs-overlays></literal> exists and is a
3636+ directory, then the result is the set of overlays found in that directory, ordered lexicographically.</para>
30373131- <para>In the directory pointed to by the Nix search path entry
3232- <literal><nixpkgs-overlays></literal>.</para>
3838+ <para>See the section on <literal>NIX_PATH</literal> in the Nix manual for more details on how to
3939+ set a value for <literal><nixpkgs-overlays>.</literal></para>
3340 </listitem>
34413542 <listitem>
3636-3737- <para>In the directory <filename>~/.config/nixpkgs/overlays/</filename>.</para>
4343+ <para>Otherwise, if <filename>~/.config/nixpkgs/overlays/</filename> exists and is a directory, then
4444+ the result is the set of overlays found in that directory, ordered lexicographically.</para>
3845 </listitem>
39464047</orderedlist>
4148</para>
42494343-<para>For the second and third options, the directory should contain Nix expressions defining the
4444-overlays. Each overlay can be a file, a directory containing a
4545-<filename>default.nix</filename>, or a symlink to one of those. The expressions should follow
4646-the syntax described in <xref linkend="sec-overlays-layout"/>.</para>
5050+<para>For the second and third options overlays can be provided as files,
5151+directories containing a <filename>default.nix</filename>, or symlinks to one of those.</para>
47524848-<para>The order of the overlay layers can influence the recipe of packages if multiple layers override
4949-the same recipe. In the case where overlays are loaded from a directory, they are loaded in
5050-alphabetical order.</para>
5151-5252-<para>To install an overlay using the last option, you can clone the overlay's repository and add
5353-a symbolic link to it in <filename>~/.config/nixpkgs/overlays/</filename> directory.</para>
5353+<para>The last option provides a convenient way to install an overlay from a repository,
5454+by cloning the overlay's repository and adding a symbolic link to it in
5555+<filename>~/.config/nixpkgs/overlays/</filename>.</para>
54565557</section>
56585759<!--============================================================-->
58605959-<section xml:id="sec-overlays-layout">
6060-<title>Overlays Layout</title>
6161+<section xml:id="sec-overlays-definition">
6262+<title>Defining overlays</title>
61636262-<para>Overlays are expressed as Nix functions which accept 2 arguments and return a set of
6363-packages.</para>
6464+<para>Overlays are Nix functions which accept two arguments,
6565+conventionally called <varname>self</varname> and <varname>super</varname>,
6666+and return a set of packages. For example, the following is a valid overlay.</para>
64676568<programlisting>
6669self: super:
···7578}
7679</programlisting>
77807878-<para>The first argument, usually named <varname>self</varname>, corresponds to the final package
8181+<para>The first argument (<varname>self</varname>) corresponds to the final package
7982set. You should use this set for the dependencies of all packages specified in your
8083overlay. For example, all the dependencies of <varname>rr</varname> in the example above come
8184from <varname>self</varname>, as well as the overridden dependencies used in the
8285<varname>boost</varname> override.</para>
83868484-<para>The second argument, usually named <varname>super</varname>,
8787+<para>The second argument (<varname>super</varname>)
8588corresponds to the result of the evaluation of the previous stages of
8689Nixpkgs. It does not contain any of the packages added by the current
8787-overlay nor any of the following overlays. This set should be used either
9090+overlay, nor any of the following overlays. This set should be used either
8891to refer to packages you wish to override, or to access functions defined
8992in Nixpkgs. For example, the original recipe of <varname>boost</varname>
9093in the above example, comes from <varname>super</varname>, as well as the
9194<varname>callPackage</varname> function.</para>
92959396<para>The value returned by this function should be a set similar to
9494-<filename>pkgs/top-level/all-packages.nix</filename>, which contains
9797+<filename>pkgs/top-level/all-packages.nix</filename>, containing
9598overridden and/or new packages.</para>
9999+100100+<para>Overlays are similar to other methods for customizing Nixpkgs, in particular
101101+the <literal>packageOverrides</literal> attribute described in <xref linkend="sec-modify-via-packageOverrides"/>.
102102+Indeed, <literal>packageOverrides</literal> acts as an overlay with only the
103103+<varname>super</varname> argument. It is therefore appropriate for basic use,
104104+but overlays are more powerful and easier to distribute.</para>
9610597106</section>
98107