Overlays: allow overlays to be specified in a file
This commit is contained in:
parent
060a41d225
commit
9235ff1259
|
@ -17,42 +17,68 @@ if multiple layers override the same package.</para>
|
||||||
<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 is determined as follows:
|
<para>The list of overlays is determined as follows.</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>First, if an <varname>overlays</varname> argument to the nixpkgs function itself is given,
|
<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
|
then that is used.</para>
|
||||||
<literal>import <nixpkgs> { overlays = [ overlay1 overlay2 ] }</literal>.</para>
|
|
||||||
|
|
||||||
<para>On a NixOS system the value of the <literal>nixpkgs.overlays</literal> option, if present,
|
<para>This can be passed explicitly when importing nipxkgs, for example
|
||||||
is passed to the system Nixpkgs in this way. Note that this does not affect the overlays for
|
<literal>import <nixpkgs> { overlays = [ overlay1 overlay2 ]; }</literal>.</para>
|
||||||
non-NixOS operations (e.g. <literal>nix-env</literal>), which are looked up independently.</para>
|
|
||||||
</listitem>
|
</listitem>
|
||||||
|
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>Otherwise, if the Nix path entry <literal><nixpkgs-overlays></literal> exists and is a
|
<para>Otherwise, if the Nix path entry <literal><nixpkgs-overlays></literal> exists, we look for overlays
|
||||||
directory, then the result is the set of overlays found in that directory, ordered lexicographically.</para>
|
at that path, as described below.</para>
|
||||||
|
|
||||||
<para>See the section on <literal>NIX_PATH</literal> in the Nix manual for more details on how to
|
<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>
|
set a value for <literal><nixpkgs-overlays>.</literal></para>
|
||||||
</listitem>
|
</listitem>
|
||||||
|
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>Otherwise, if <filename>~/.config/nixpkgs/overlays/</filename> exists and is a directory, then
|
<para>If one of <filename>~/.config/nixpkgs/overlays.nix</filename> and
|
||||||
the result is the set of overlays found in that directory, ordered lexicographically.</para>
|
<filename>~/.config/nixpkgs/overlays/</filename> exists, then we look for overlays at that path, as
|
||||||
|
described below. It is an error if both exist.</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
|
|
||||||
</orderedlist>
|
</orderedlist>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>For the second and third options, overlays are extracted from the given directory as files,
|
<para>If we are looking for overlays at a path, then there are two cases:
|
||||||
directories containing a <filename>default.nix</filename>, or symlinks to one of those.</para>
|
<itemizedlist>
|
||||||
|
<listitem>
|
||||||
|
<para>If the path is a file, then the file is imported as a Nix expression and used as the list of
|
||||||
|
overlays.</para>
|
||||||
|
</listitem>
|
||||||
|
|
||||||
<para>The last option provides a convenient way to install an overlay from a repository,
|
<listitem>
|
||||||
by cloning the overlay's repository and adding a symbolic link to it in
|
<para>If the path is a directory, then we take the content of the directory, order it
|
||||||
<filename>~/.config/nixpkgs/overlays/</filename>.</para>
|
lexicographically, and attempt to interpret each as an overlay by:
|
||||||
|
<itemizedlist>
|
||||||
|
<listitem>
|
||||||
|
<para>Importing the file, if it is a <literal>.nix</literal> file.</para>
|
||||||
|
</listitem>
|
||||||
|
<listitem>
|
||||||
|
<para>Importing a top-level <filename>default.nix</filename> file, if it is a directory.</para>
|
||||||
|
</listitem>
|
||||||
|
</itemizedlist>
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</itemizedlist>
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<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 looked up independently.</para>
|
||||||
|
|
||||||
|
<para>The <filename>overlays.nix</filename> option therefore provides a convenient way to use 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>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
|
@ -40,18 +40,36 @@ in
|
||||||
# collections of packages. These collection of packages are part of the
|
# collections of packages. These collection of packages are part of the
|
||||||
# fix-point made by Nixpkgs.
|
# fix-point made by Nixpkgs.
|
||||||
overlays ? let
|
overlays ? let
|
||||||
dirPath = try (if pathExists <nixpkgs-overlays> then <nixpkgs-overlays> else "") "";
|
isDir = path: pathExists (path + "/.");
|
||||||
dirHome = homeDir + "/.config/nixpkgs/overlays";
|
pathOverlays = try <nixpkgs-overlays> "";
|
||||||
dirCheck = dir: dir != "" && pathExists (dir + "/.");
|
homeOverlaysFile = homeDir + "/.config/nixpkgs/overlays.nix";
|
||||||
overlays = dir:
|
homeOverlaysDir = homeDir + "/.config/nixpkgs/overlays";
|
||||||
let content = readDir dir; in
|
overlays = path:
|
||||||
map (n: import (dir + ("/" + n)))
|
# check if the path is a directory or a file
|
||||||
(builtins.filter (n: builtins.match ".*\.nix" n != null || pathExists (dir + ("/" + n + "/default.nix")))
|
if isDir path then
|
||||||
(attrNames content));
|
# it's a directory, so the set of overlays from the directory, ordered lexicographically
|
||||||
|
let content = readDir path; in
|
||||||
|
map (n: import (path + ("/" + n)))
|
||||||
|
(builtins.filter (n: builtins.match ".*\.nix" n != null || pathExists (path + ("/" + n + "/default.nix")))
|
||||||
|
(attrNames content))
|
||||||
|
else
|
||||||
|
# it's a file, so the result is the contents of the file itself
|
||||||
|
import path;
|
||||||
in
|
in
|
||||||
if dirPath != "" then
|
if pathOverlays != "" && pathExists pathOverlays then overlays pathOverlays
|
||||||
overlays dirPath
|
else if pathExists homeOverlaysFile && pathExists homeOverlaysDir then
|
||||||
else if dirCheck dirHome then overlays dirHome
|
throw ''
|
||||||
|
Nixpkgs overlays can be specified with ${homeOverlaysFile} or ${homeOverlaysDir}, but not both.
|
||||||
|
Please remove one of them and try again.
|
||||||
|
''
|
||||||
|
else if pathExists homeOverlaysFile then
|
||||||
|
if isDir homeOverlaysFile then
|
||||||
|
throw (homeOverlaysFile + " should be a file")
|
||||||
|
else overlays homeOverlaysFile
|
||||||
|
else if pathExists homeOverlaysDir then
|
||||||
|
if !(isDir homeOverlaysDir) then
|
||||||
|
throw (homeOverlaysDir + " should be a directory")
|
||||||
|
else overlays homeOverlaysDir
|
||||||
else []
|
else []
|
||||||
|
|
||||||
, ...
|
, ...
|
||||||
|
|
Loading…
Reference in a new issue