lib.packagesFromDirectoryRecursive: Allow non-"path" directory (#406885)

This commit is contained in:
jade
2025-07-10 16:38:36 -07:00
committed by GitHub
2 changed files with 30 additions and 3 deletions
+2 -3
View File
@@ -385,7 +385,6 @@ in
recurseIntoAttrs
removeSuffix
;
inherit (lib.path) append;
# Generate an attrset corresponding to a given directory.
# This function is outside `packagesFromDirectoryRecursive`'s lambda expression,
@@ -396,7 +395,7 @@ in
name: type:
# for each directory entry
let
path = append directory name;
path = directory + "/${name}";
in
if type == "directory" then
{
@@ -429,7 +428,7 @@ in
directory,
}@args:
let
defaultPath = append directory "package.nix";
defaultPath = directory + "/package.nix";
in
if pathExists defaultPath then
# if `${directory}/package.nix` exists, call it directly
+28
View File
@@ -4158,6 +4158,34 @@ runTests {
};
};
# Make sure that passing a string for the `directory` works.
#
# See: https://github.com/NixOS/nixpkgs/pull/361424#discussion_r1934813568
# See: https://github.com/NixOS/nix/issues/9428
testPackagesFromDirectoryRecursiveStringDirectory = {
expr = packagesFromDirectoryRecursive {
callPackage = path: overrides: import path overrides;
# Do NOT remove the `builtins.toString` call here!!!
directory = builtins.toString ./packages-from-directory/plain;
};
expected = {
a = "a";
b = "b";
# Note: Other files/directories in `./test-data/c/` are ignored and can be
# used by `package.nix`.
c = "c";
my-namespace = {
d = "d";
e = "e";
f = "f";
my-sub-namespace = {
g = "g";
h = "h";
};
};
};
};
# Check that `packagesFromDirectoryRecursive` can process a directory with a
# top-level `package.nix` file into a single package.
testPackagesFromDirectoryRecursiveTopLevelPackageNix = {