summaryrefslogtreecommitdiffstats
path: root/pkgs/top-level/impure.nix
diff options
context:
space:
mode:
authorMichael Peyton Jones <michaelpj@gmail.com>2017-08-09 19:47:27 +0100
committerNicolas B. Pierron <nicolas.b.pierron@gmail.com>2017-08-17 22:13:39 +0000
commit9235ff1259bb9425c58ac3b3322ddf83e74a4255 (patch)
tree6a1ed891c2632e58d539924897ad21ac51707659 /pkgs/top-level/impure.nix
parent060a41d225b099cd843bea1b431dc7aae8ed1d1a (diff)
Overlays: allow overlays to be specified in a file
Diffstat (limited to 'pkgs/top-level/impure.nix')
-rw-r--r--pkgs/top-level/impure.nix40
1 files changed, 29 insertions, 11 deletions
diff --git a/pkgs/top-level/impure.nix b/pkgs/top-level/impure.nix
index c0cf8fb09113..a4d313a1b991 100644
--- a/pkgs/top-level/impure.nix
+++ b/pkgs/top-level/impure.nix
@@ -40,18 +40,36 @@ in
# collections of packages. These collection of packages are part of the
# fix-point made by Nixpkgs.
overlays ? let
- dirPath = try (if pathExists <nixpkgs-overlays> then <nixpkgs-overlays> else "") "";
- dirHome = homeDir + "/.config/nixpkgs/overlays";
- dirCheck = dir: dir != "" && pathExists (dir + "/.");
- overlays = dir:
- let content = readDir dir; in
- map (n: import (dir + ("/" + n)))
- (builtins.filter (n: builtins.match ".*\.nix" n != null || pathExists (dir + ("/" + n + "/default.nix")))
- (attrNames content));
+ isDir = path: pathExists (path + "/.");
+ pathOverlays = try <nixpkgs-overlays> "";
+ homeOverlaysFile = homeDir + "/.config/nixpkgs/overlays.nix";
+ homeOverlaysDir = homeDir + "/.config/nixpkgs/overlays";
+ overlays = path:
+ # check if the path is a directory or a file
+ if isDir path then
+ # 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
- if dirPath != "" then
- overlays dirPath
- else if dirCheck dirHome then overlays dirHome
+ if pathOverlays != "" && pathExists pathOverlays then overlays pathOverlays
+ else if pathExists homeOverlaysFile && pathExists homeOverlaysDir then
+ 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 []
, ...