diff --git a/doc/overlays.xml b/doc/overlays.xml
index f8f554bb5569..6d631071c345 100644
--- a/doc/overlays.xml
+++ b/doc/overlays.xml
@@ -8,59 +8,62 @@
overlays. Overlays are used to add layers in the fix-point used by Nixpkgs
to compose the set of all packages.
+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.
+
-Installing Overlays
+Installing overlays
-The set of overlays is looked for in the following places. The
-first one present is considered, and all the rest are ignored:
+The list of overlays is determined as follows:
+ First, if an overlays argument to the nixpkgs function itself is given,
+ then that is used. This can be passed explicitly when importing nipxkgs, for example
+ import <nixpkgs> { overlays = [ overlay1 overlay2 ] }.
- As an argument of the imported attribute set. When importing Nixpkgs,
- the overlays attribute argument can be set to a list of
- functions, which is described in .
-
+ On a NixOS system the value of the nixpkgs.overlays 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. nix-env), which are looked up independently.
+ Otherwise, if the Nix path entry <nixpkgs-overlays> exists and is a
+ directory, then the result is the set of overlays found in that directory, ordered lexicographically.
- In the directory pointed to by the Nix search path entry
- <nixpkgs-overlays>.
+ See the section on NIX_PATH in the Nix manual for more details on how to
+ set a value for <nixpkgs-overlays>.
-
- In the directory ~/.config/nixpkgs/overlays/.
+ Otherwise, if ~/.config/nixpkgs/overlays/ exists and is a directory, then
+ the result is the set of overlays found in that directory, ordered lexicographically.
-For the second and third options, the directory should contain Nix expressions defining the
-overlays. Each overlay can be a file, a directory containing a
-default.nix, or a symlink to one of those. The expressions should follow
-the syntax described in .
+For the second and third options overlays can be provided as files,
+directories containing a default.nix, or symlinks to one of those.
-The order of the overlay layers can influence the recipe of packages if multiple layers override
-the same recipe. In the case where overlays are loaded from a directory, they are loaded in
-alphabetical order.
-
-To install an overlay using the last option, you can clone the overlay's repository and add
-a symbolic link to it in ~/.config/nixpkgs/overlays/ directory.
+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
+~/.config/nixpkgs/overlays/.
-
-Overlays Layout
+
+Defining overlays
-Overlays are expressed as Nix functions which accept 2 arguments and return a set of
-packages.
+Overlays are Nix functions which accept two arguments,
+conventionally called self and super,
+and return a set of packages. For example, the following is a valid overlay.
self: super:
@@ -75,25 +78,31 @@ self: super:
}
-The first argument, usually named self, corresponds to the final package
+The first argument (self) corresponds to the final package
set. You should use this set for the dependencies of all packages specified in your
overlay. For example, all the dependencies of rr in the example above come
from self, as well as the overridden dependencies used in the
boost override.
-The second argument, usually named super,
+The second argument (super)
corresponds to the result of the evaluation of the previous stages of
Nixpkgs. It does not contain any of the packages added by the current
-overlay nor any of the following overlays. This set should be used either
+overlay, nor any of the following overlays. This set should be used either
to refer to packages you wish to override, or to access functions defined
in Nixpkgs. For example, the original recipe of boost
in the above example, comes from super, as well as the
callPackage function.
The value returned by this function should be a set similar to
-pkgs/top-level/all-packages.nix, which contains
+pkgs/top-level/all-packages.nix, containing
overridden and/or new packages.
+Overlays are similar to other methods for customizing Nixpkgs, in particular
+the packageOverrides attribute described in .
+Indeed, packageOverrides acts as an overlay with only the
+super argument. It is therefore appropriate for basic use,
+but overlays are more powerful and easier to distribute.
+