lib.packagesFromDirectoryRecursive: add tests for nested scopes

nicoo 41f219d1 6b7576b0

Changed files
+58
lib
tests
packages-from-directory
+34
lib/tests/misc.nix
···
checkC = false;
};
};
+
+
# Check that `packagesFromDirectoryRecursive` can be used to create scopes
+
# for sub-directories
+
testPackagesFromDirectoryNestedScopes = let
+
inherit (lib) makeScope recurseIntoAttrs;
+
emptyScope = makeScope lib.callPackageWith (_: {});
+
in {
+
expr = lib.filterAttrsRecursive (name: value: !lib.elem name [ "callPackage" "newScope" "overrideScope" "packages" ]) (packagesFromDirectoryRecursive {
+
inherit (emptyScope) callPackage newScope;
+
recurseIntoDirectory = f: { newScope, ... }@args:
+
recurseIntoAttrs (makeScope newScope (self:
+
f (args // {
+
inherit (self) callPackage newScope;
+
})
+
));
+
directory = ./packages-from-directory/scope;
+
});
+
expected = lib.recurseIntoAttrs {
+
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 = lib.recurseIntoAttrs {
+
d = "d";
+
e = "e";
+
f = "f";
+
my-sub-namespace = lib.recurseIntoAttrs {
+
g = "g";
+
h = "h";
+
};
+
};
+
};
+
};
+1
lib/tests/packages-from-directory/scope/a.nix
···
+
{ }: "a"
+3
lib/tests/packages-from-directory/scope/b.nix
···
+
{ a }:
+
assert a == "a";
+
"b"
lib/tests/packages-from-directory/scope/c/my-extra-feature.patch

This is a binary file and will not be displayed.

+1
lib/tests/packages-from-directory/scope/c/not-a-namespace/not-a-package.nix
···
+
{ }
+1
lib/tests/packages-from-directory/scope/c/package.nix
···
+
{ }: "c"
+1
lib/tests/packages-from-directory/scope/c/support-definitions.nix
···
+
{ }
+5
lib/tests/packages-from-directory/scope/my-namespace/d.nix
···
+
{ a, e }:
+
# Check we can get parameter from the parent scope(s) as well as the current one
+
assert a == "a";
+
assert e == "e";
+
"d"
+3
lib/tests/packages-from-directory/scope/my-namespace/e.nix
···
+
{ d }:
+
# Check that mutual recursion is possible
+
"e"
+1
lib/tests/packages-from-directory/scope/my-namespace/f/package.nix
···
+
{ }: "f"
+7
lib/tests/packages-from-directory/scope/my-namespace/my-sub-namespace/g.nix
···
+
{
+
a,
+
d,
+
h,
+
}:
+
# Check we can get parameters from ancestral scopes (e.g. the scope's grandparent)
+
"g"
+1
lib/tests/packages-from-directory/scope/my-namespace/my-sub-namespace/h.nix
···
+
{ }: "h"