Skip to content

Commit

Permalink
squash! lib.packagesFromDirectoryRecursive: hoist processDir out of…
Browse files Browse the repository at this point in the history
… the lambda

also hoisted the default `recurseIntoDirectory`, as requested during review
  • Loading branch information
nbraud committed Jan 12, 2025
1 parent 91f94d8 commit d742f77
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions lib/filesystem.nix
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,23 @@ in
lib.filesystem.packagesFromDirectoryRecursive: Unsupported file type ${type} at path ${toString path}
''
) (builtins.readDir directory);

defaultRecurse = processDir: args:
if args ? newScope then
# Create a new scope and mark it `recurseForDerivations`.
# This lets the packages refer to each other.
# See:
# [lib.makeScope](https://nixos.org/manual/nixpkgs/unstable/#function-library-lib.customisation.makeScope) and
# [lib.recurseIntoAttrs](https://nixos.org/manual/nixpkgs/unstable/#function-library-lib.customisation.makeScope)
recurseIntoAttrs (makeScope args.newScope (self:
# generate the attrset representing the directory, using the new scope's `callPackage` and `newScope`
processDir (args // {
inherit (self) callPackage newScope;
})
))
else
processDir args
;
in
{
callPackage,
Expand All @@ -462,25 +479,7 @@ in
# recurseIntoDirectory can modify the function used when processing directory entries
# and recurseArgs can (optionally) hold data for its use ; see function documentation
recurseArgs ? throw "lib.packagesFromDirectoryRecursive: recurseArgs wasn't passed in args",
recurseIntoDirectory ?
if args ? newScope then
# `processDir` is the same function as defined above
# `args` are the arguments passed to (this recursive call of) `packagesFromDirectoryRecursive`
processDir: { newScope, ... }@args:
# Create a new scope and mark it `recurseForDerivations`.
# This lets the packages refer to each other.
# See:
# [lib.makeScope](https://nixos.org/manual/nixpkgs/unstable/#function-library-lib.customisation.makeScope) and
# [lib.recurseIntoAttrs](https://nixos.org/manual/nixpkgs/unstable/#function-library-lib.customisation.makeScope)
recurseIntoAttrs (makeScope newScope (self:
# generate the attrset representing the directory, using the new scope's `callPackage` and `newScope`
processDir (args // {
inherit (self) callPackage newScope;
})
))
else
# otherwise, no modification is necessary
id,
recurseIntoDirectory ? defaultRecurse,
}@args:
let
defaultPath = append directory "package.nix";
Expand Down

0 comments on commit d742f77

Please sign in to comment.