diff options
author | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-10-10 19:10:02 +0200 |
---|---|---|
committer | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-10-24 01:44:04 +0200 |
commit | f4e0043049523dba68eba917edd2f7e322ab0c2e (patch) | |
tree | ba7010932c58ed322bfbd5d48fe74e6ed65755c2 /lib/fileset/internal.nix | |
parent | 5fb487096d9357584365216e0485c421f50dcba0 (diff) |
lib.fileset.fileFilter: init
Diffstat (limited to 'lib/fileset/internal.nix')
-rw-r--r-- | lib/fileset/internal.nix | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/fileset/internal.nix b/lib/fileset/internal.nix index 9892172955c36..2d52a8cb410b1 100644 --- a/lib/fileset/internal.nix +++ b/lib/fileset/internal.nix @@ -638,4 +638,30 @@ rec { else # In all other cases it's the rhs rhs; + + _fileFilter = predicate: fileset: + let + recurse = path: tree: + mapAttrs (name: subtree: + if isAttrs subtree || subtree == "directory" then + recurse (path + "/${name}") subtree + else if + predicate { + inherit name; + type = subtree; + # To ensure forwards compatibility with more arguments being added in the future, + # adding an attribute which can't be deconstructed :) + "lib.fileset.fileFilter: The predicate function passed as the first argument must be able to handle extra attributes for future compatibility. If you're using `{ name, file }:`, use `{ name, file, ... }:` instead." = null; + } + then + subtree + else + null + ) (_directoryEntries path tree); + in + if fileset._internalIsEmptyWithoutBase then + _emptyWithoutBase + else + _create fileset._internalBase + (recurse fileset._internalBase fileset._internalTree); } |