Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Comment on lines +42 to +45

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
isDir = path: {
symlink = builtins.pathExists (toString path + "/");
directory = true;
}.${pathType path} or false;
isDir = path: {
# This is hacky but the only way to check the path type of a symlink target
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
Comment on lines -68 to +79

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This leads to a worse error message, the isDir check should be kept because of that.

else []

, crossOverlays ? []
Expand Down