Skip to content

Commit

Permalink
top-level/impure.nix: fix overlay directory check
Browse files Browse the repository at this point in the history
nix 2.16 and newer return true for `pathExists (path + "/.")` regardless
of whether `path` is a file or directory.
  • Loading branch information
arcnmx committed Sep 1, 2023
1 parent 6221aed commit eace1c0
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions pkgs/top-level/impure.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,35 @@ 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 <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 = 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
Expand All @@ -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 ? []
Expand Down

0 comments on commit eace1c0

Please sign in to comment.