diff --git a/pkgs/top-level/impure.nix b/pkgs/top-level/impure.nix index 4d847e280f4b9..ff6a296bf095b 100644 --- a/pkgs/top-level/impure.nix +++ b/pkgs/top-level/impure.nix @@ -37,7 +37,12 @@ in # collections of packages. These collection of packages are part of the # fix-point made by Nixpkgs. overlays ? let - isDir = path: builtins.pathExists (path + "/."); + lib = import ../../lib; + inherit (lib.filesystem) pathType; + isDir = path: { + symlink = builtins.pathExists (toString path + "/"); + directory = true; + }.${pathType path} or false; pathOverlays = try (toString ) ""; homeOverlaysFile = homeDir + "/.config/nixpkgs/overlays.nix"; homeOverlaysDir = homeDir + "/.config/nixpkgs/overlays"; @@ -45,18 +50,22 @@ in # 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 = builtins.readDir path; in - map (n: import (path + ("/" + n))) - (builtins.filter - (n: - (builtins.match ".*\\.nix" n != null && - # ignore Emacs lock files (.#foo.nix) - builtins.match "\\.#.*" n == null) || - builtins.pathExists (path + ("/" + n + "/default.nix"))) - (builtins.attrNames content)) + overlaysDir path else # it's a file, so the result is the contents of the file itself - import path; + overlaysFile path; + overlaysDir = path: + let content = builtins.readDir path; in + map (n: import (path + ("/" + n))) + (builtins.filter + (n: + (builtins.match ".*\\.nix" n != null && + # ignore Emacs lock files (.#foo.nix) + builtins.match "\\.#.*" n == null) || + builtins.pathExists (path + ("/" + n + "/default.nix"))) + (builtins.attrNames content)); + overlaysFile = path: + import path; in if pathOverlays != "" && builtins.pathExists pathOverlays then overlays pathOverlays else if builtins.pathExists homeOverlaysFile && builtins.pathExists homeOverlaysDir then @@ -65,13 +74,9 @@ in Please remove one of them and try again. '' else if builtins.pathExists homeOverlaysFile then - if isDir homeOverlaysFile then - throw (homeOverlaysFile + " should be a file") - else overlays homeOverlaysFile + overlaysFile homeOverlaysFile else if builtins.pathExists homeOverlaysDir then - if !(isDir homeOverlaysDir) then - throw (homeOverlaysDir + " should be a directory") - else overlays homeOverlaysDir + overlaysDir homeOverlaysDir else [] , crossOverlays ? []