Skip to content

Commit

Permalink
lib.packagesFromDirectoryRecursive: let-bind functions called from lib
Browse files Browse the repository at this point in the history
I was told it is better for eval performance:
  #361424 (comment)
  • Loading branch information
nbraud committed Dec 12, 2024
1 parent 1507e5a commit 6b8521e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/filesystem.nix
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,14 @@ in
...
}:
let
inherit (lib) concatMapAttrs removeSuffix;
inherit (lib.path) append;
defaultPath = append directory "package.nix";
in
if pathExists defaultPath then
# if `${directory}/package.nix` exists, call it directly
callPackage defaultPath {}
else lib.concatMapAttrs (name: type:
else concatMapAttrs (name: type:
# otherwise, for each directory entry
let path = append directory name; in
if type == "directory" then {
Expand All @@ -381,7 +382,7 @@ in
};
} else if type == "regular" && hasSuffix ".nix" name then {
# call .nix files
"${lib.removeSuffix ".nix" name}" = callPackage path {};
"${removeSuffix ".nix" name}" = callPackage path {};
} else if type == "regular" then {
# ignore non-nix files
} else throw ''
Expand Down

0 comments on commit 6b8521e

Please sign in to comment.