doc: Improve overrides and overlays documentation

This commit is contained in:
Robert Hensing 2018-10-18 14:01:06 +02:00
parent 9b7654f6ff
commit 3c2ae189c2
2 changed files with 114 additions and 92 deletions

View File

@ -10,12 +10,9 @@
</para> </para>
<para> <para>
These overriding functions let you focus on one part of Nixpkgs and give you These functions are used to make changes to packages, returning only single
back the requested variation. This is orthogonal but related to overlays and packages. Overlays, on the other hand, can be used to combine the overridden
the extending functions. Those also let you make modifications but return the packages across the entire package set of Nixpkgs.
whole package set instead of just what you modified. When used together, the
override functions make the changes and overlays or extending functions add
those changes to the package sets.
</para> </para>
<section xml:id="sec-pkg-override"> <section xml:id="sec-pkg-override">

View File

@ -16,47 +16,72 @@
<section xml:id="sec-overlays-install"> <section xml:id="sec-overlays-install">
<title>Installing overlays</title> <title>Installing overlays</title>
<para>
The list of overlays can be set either explicitly in a Nix expression, or
through <literal>&lt;nixpkgs-overlays></literal> or user configuration
files.
</para>
<section xml:id="sec-overlays-argument">
<title>Set overlays in NixOS or Nix expressions</title>
<para>
On a NixOS system the value of the <literal>nixpkgs.overlays</literal>
option, if present, is passed to the system Nixpkgs directly as an
argument. Note that this does not affect the overlays for non-NixOS
operations (e.g. <literal>nix-env</literal>), which are
<link xlink:href="#sec-overlays-lookup">looked</link> up independently.
</para>
<para>
The list of overlays can be passed explicitly when importing nixpkgs, for
example <literal>import &lt;nixpkgs> { overlays = [ overlay1 overlay2 ];
}</literal>.
</para>
<para>
Further overlays can be added by calling the <literal>pkgs.extend</literal>
or <literal>pkgs.appendOverlays</literal>, although it is often preferable
to avoid these functions, because they recompute the Nixpkgs fixpoint,
which is somewhat expensive to do.
</para>
</section>
<section xml:id="sec-overlays-lookup">
<title>Install overlays via configuration lookup</title>
<para> <para>
The list of overlays is determined as follows. The list of overlays is determined as follows.
</para> </para>
<para> <para>
If the <varname>overlays</varname> argument is not provided explicitly, we
look for overlays in a path. The path is determined as follows:
<orderedlist> <orderedlist>
<listitem> <listitem>
<para> <para>
First, if an <varname>overlays</varname> argument to the nixpkgs function First, if an
itself is given, then that is used. <link xlink:href="#sec-overlays-argument"><varname>overlays</varname>
</para> argument</link> to the nixpkgs function itself is given, then that is
<para> used and no path lookup will be performed.
This can be passed explicitly when importing nixpkgs, for example
<literal>import &lt;nixpkgs> { overlays = [ overlay1 overlay2 ];
}</literal>.
</para>
<para>
Further overlays can be added by calling the
<literal>pkgs.extend</literal> or <literal>pkgs.appendOverlays</literal>,
although it is often preferable to avoid these functions, because they
recompute the Nixpkgs fixpoint, which is somewhat expensive to do.
</para> </para>
</listitem> </listitem>
<listitem> <listitem>
<para> <para>
Otherwise, if the Nix path entry <literal>&lt;nixpkgs-overlays></literal> Otherwise, if the Nix path entry
exists, we look for overlays at that path, as described below. <literal>&lt;nixpkgs-overlays></literal> exists, we look for overlays at
that path, as described below.
</para> </para>
<para> <para>
See the section on <literal>NIX_PATH</literal> in the Nix manual for more See the section on <literal>NIX_PATH</literal> in the Nix manual for
details on how to set a value for more details on how to set a value for
<literal>&lt;nixpkgs-overlays>.</literal> <literal>&lt;nixpkgs-overlays>.</literal>
</para> </para>
</listitem> </listitem>
<listitem> <listitem>
<para> <para>
If one of <filename>~/.config/nixpkgs/overlays.nix</filename> and If one of <filename>~/.config/nixpkgs/overlays.nix</filename> and
<filename>~/.config/nixpkgs/overlays/</filename> exists, then we look for <filename>~/.config/nixpkgs/overlays/</filename> exists, then we look
overlays at that path, as described below. It is an error if both exist. for overlays at that path, as described below. It is an error if both
exist.
</para> </para>
</listitem> </listitem>
</orderedlist> </orderedlist>
@ -95,19 +120,19 @@
</para> </para>
<para> <para>
On a NixOS system the value of the <literal>nixpkgs.overlays</literal> Because overlays that are set in NixOS configuration do not affect
option, if present, is passed to the system Nixpkgs directly as an argument. non-NixOS operations such as <literal>nix-env</literal>, the
Note that this does not affect the overlays for non-NixOS operations (e.g. <filename>overlays.nix</filename> option provides a convenient way to use
<literal>nix-env</literal>), which are looked up independently. the same overlays for a NixOS system configuration and user configuration:
the same file can be used as <filename>overlays.nix</filename> and imported
as the value of <literal>nixpkgs.overlays</literal>.
</para> </para>
<para> <!-- TODO: Example of sharing overlays between NixOS configuration
The <filename>overlays.nix</filename> option therefore provides a convenient and configuration lookup. Also reference the example
way to use the same overlays for a NixOS system configuration and user from the sec-overlays-argument paragraph about NixOS.
configuration: the same file can be used as -->
<filename>overlays.nix</filename> and imported as the value of </section>
<literal>nixpkgs.overlays</literal>.
</para>
</section> </section>
<!--============================================================--> <!--============================================================-->
<section xml:id="sec-overlays-definition"> <section xml:id="sec-overlays-definition">