lib.packagesFromDirectoryRecursive: let-bind functions called from lib

I was told it is better for eval performance:
  https://github.com/NixOS/nixpkgs/pull/361424#discussion_r1879975642
This commit is contained in:
nicoo 2024-12-12 18:02:21 +00:00
parent 1db8650fb4
commit 065b48084f

View file

@ -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 {
@ -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 ''