Skip to content

Commit

Permalink
lib.packagesFromDirectoryRecursive: default to creating new scopes wh…
Browse files Browse the repository at this point in the history
…en `newScope` is provided
  • Loading branch information
nbraud committed Dec 1, 2024
1 parent ca8dad6 commit 57b51d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
19 changes: 12 additions & 7 deletions lib/filesystem.nix
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,6 @@ in
packagesFromDirectoryRecursive {
inherit (pkgs) callPackage newScope;
recurseIntoDirectory = f: { newScope, ... }@args:
lib.recurseIntoAttrset (lib.makeScope newScope (self:
f (args // {
inherit (self) callPackage newScope;
})
));
directory = ./my-packages;
}
=> { ... }
Expand All @@ -366,7 +360,18 @@ in
{
callPackage,
directory,
recurseIntoDirectory ? lib.id,
recurseIntoDirectory ?
if args ? newScope then
# when `newScope` is provided, create a new scope when recursing into a directory (incl. the top one)
f: { newScope, ... }@args:
lib.recurseIntoAttrset (lib.makeScope newScope (self:
f (args // {
inherit (self) callPackage newScope;
})
))
else
# otherwise, perform as usual
lib.id,
...
}@args:
if !pathIsDirectory directory then
Expand Down
6 changes: 0 additions & 6 deletions lib/tests/misc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2529,12 +2529,6 @@ runTests {
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 {
Expand Down

0 comments on commit 57b51d0

Please sign in to comment.