···8overlays. Overlays are used to add layers in the fix-point used by Nixpkgs
9to compose the set of all packages.</para>
10000011<!--============================================================-->
1213<section xml:id="sec-overlays-install">
14-<title>Installing Overlays</title>
1516-<para>The set of overlays is looked for in the following places. The
17-first one present is considered, and all the rest are ignored:
1819<orderedlist>
2021 <listitem>
22-23- <para>As an argument of the imported attribute set. When importing Nixpkgs,
24- the <varname>overlays</varname> attribute argument can be set to a list of
25- functions, which is described in <xref linkend="sec-overlays-layout"/>.</para>
2600027 </listitem>
2829 <listitem>
003031- <para>In the directory pointed to by the Nix search path entry
32- <literal><nixpkgs-overlays></literal>.</para>
33 </listitem>
3435 <listitem>
36-37- <para>In the directory <filename>~/.config/nixpkgs/overlays/</filename>.</para>
38 </listitem>
3940</orderedlist>
41</para>
4243-<para>For the second and third options, the directory should contain Nix expressions defining the
44-overlays. Each overlay can be a file, a directory containing a
45-<filename>default.nix</filename>, or a symlink to one of those. The expressions should follow
46-the syntax described in <xref linkend="sec-overlays-layout"/>.</para>
4748-<para>The order of the overlay layers can influence the recipe of packages if multiple layers override
49-the same recipe. In the case where overlays are loaded from a directory, they are loaded in
50-alphabetical order.</para>
51-52-<para>To install an overlay using the last option, you can clone the overlay's repository and add
53-a symbolic link to it in <filename>~/.config/nixpkgs/overlays/</filename> directory.</para>
5455</section>
5657<!--============================================================-->
5859-<section xml:id="sec-overlays-layout">
60-<title>Overlays Layout</title>
6162-<para>Overlays are expressed as Nix functions which accept 2 arguments and return a set of
63-packages.</para>
06465<programlisting>
66self: super:
···75}
76</programlisting>
7778-<para>The first argument, usually named <varname>self</varname>, corresponds to the final package
79set. You should use this set for the dependencies of all packages specified in your
80overlay. For example, all the dependencies of <varname>rr</varname> in the example above come
81from <varname>self</varname>, as well as the overridden dependencies used in the
82<varname>boost</varname> override.</para>
8384-<para>The second argument, usually named <varname>super</varname>,
85corresponds to the result of the evaluation of the previous stages of
86Nixpkgs. It does not contain any of the packages added by the current
87-overlay nor any of the following overlays. This set should be used either
88to refer to packages you wish to override, or to access functions defined
89in Nixpkgs. For example, the original recipe of <varname>boost</varname>
90in the above example, comes from <varname>super</varname>, as well as the
91<varname>callPackage</varname> function.</para>
9293<para>The value returned by this function should be a set similar to
94-<filename>pkgs/top-level/all-packages.nix</filename>, which contains
95overridden and/or new packages.</para>
0000009697</section>
98
···8overlays. Overlays are used to add layers in the fix-point used by Nixpkgs
9to compose the set of all packages.</para>
1011+<para>Nixpkgs can be configured with a list of overlays, which are
12+applied in order. This means that the order of the overlays can be significant
13+if multiple layers override the same package.</para>
14+15<!--============================================================-->
1617<section xml:id="sec-overlays-install">
18+<title>Installing overlays</title>
1920+<para>The list of overlays is determined as follows:
02122<orderedlist>
2324 <listitem>
25+ <para>First, if an <varname>overlays</varname> argument to the nixpkgs function itself is given,
26+ then that is used. This can be passed explicitly when importing nipxkgs, for example
27+ <literal>import <nixpkgs> { overlays = [ overlay1 overlay2 ] }</literal>.</para>
02829+ <para>On a NixOS system the value of the <literal>nixpkgs.overlays</literal> option, if present,
30+ is passed to the system Nixpkgs in this way. Note that this does not affect the overlays for
31+ non-NixOS operations (e.g. <literal>nix-env</literal>), which are looked up independently.</para>
32 </listitem>
3334 <listitem>
35+ <para>Otherwise, if the Nix path entry <literal><nixpkgs-overlays></literal> exists and is a
36+ directory, then the result is the set of overlays found in that directory, ordered lexicographically.</para>
3738+ <para>See the section on <literal>NIX_PATH</literal> in the Nix manual for more details on how to
39+ set a value for <literal><nixpkgs-overlays>.</literal></para>
40 </listitem>
4142 <listitem>
43+ <para>Otherwise, if <filename>~/.config/nixpkgs/overlays/</filename> exists and is a directory, then
44+ the result is the set of overlays found in that directory, ordered lexicographically.</para>
45 </listitem>
4647</orderedlist>
48</para>
4950+<para>For the second and third options overlays can be provided as files,
51+directories containing a <filename>default.nix</filename>, or symlinks to one of those.</para>
005253+<para>The last option provides a convenient way to install an overlay from a repository,
54+by cloning the overlay's repository and adding a symbolic link to it in
55+<filename>~/.config/nixpkgs/overlays/</filename>.</para>
0005657</section>
5859<!--============================================================-->
6061+<section xml:id="sec-overlays-definition">
62+<title>Defining overlays</title>
6364+<para>Overlays are Nix functions which accept two arguments,
65+conventionally called <varname>self</varname> and <varname>super</varname>,
66+and return a set of packages. For example, the following is a valid overlay.</para>
6768<programlisting>
69self: super:
···78}
79</programlisting>
8081+<para>The first argument (<varname>self</varname>) corresponds to the final package
82set. You should use this set for the dependencies of all packages specified in your
83overlay. For example, all the dependencies of <varname>rr</varname> in the example above come
84from <varname>self</varname>, as well as the overridden dependencies used in the
85<varname>boost</varname> override.</para>
8687+<para>The second argument (<varname>super</varname>)
88corresponds to the result of the evaluation of the previous stages of
89Nixpkgs. It does not contain any of the packages added by the current
90+overlay, nor any of the following overlays. This set should be used either
91to refer to packages you wish to override, or to access functions defined
92in Nixpkgs. For example, the original recipe of <varname>boost</varname>
93in the above example, comes from <varname>super</varname>, as well as the
94<varname>callPackage</varname> function.</para>
9596<para>The value returned by this function should be a set similar to
97+<filename>pkgs/top-level/all-packages.nix</filename>, containing
98overridden and/or new packages.</para>
99+100+<para>Overlays are similar to other methods for customizing Nixpkgs, in particular
101+the <literal>packageOverrides</literal> attribute described in <xref linkend="sec-modify-via-packageOverrides"/>.
102+Indeed, <literal>packageOverrides</literal> acts as an overlay with only the
103+<varname>super</varname> argument. It is therefore appropriate for basic use,
104+but overlays are more powerful and easier to distribute.</para>
105106</section>
107