diff options
author | Silvan Mosberger <contact@infinisil.com> | 2023-11-14 07:42:59 +0100 |
---|---|---|
committer | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-11-15 01:20:36 +0100 |
commit | 1c3eb9eff1b864bf49c3661558b495235fc3b3b4 (patch) | |
tree | 8d72c4ef51a603588ec1c9dab6fde4a323369872 /lib/fileset/default.nix | |
parent | b5953ae45d2de05b33eba1e7b2c2a198f12e0c29 (diff) |
lib.fileset.fileFilter: Restrict second argument to paths
While this change is backwards-incompatible, I think it's okay because: - The `fileFilter` function is not yet in a stable NixOS release, it was only merged about [a month ago](https://github.com/NixOS/nixpkgs/pull/257356). - All public uses of the function on GitHub only pass a path - Any `fileFilter pred fileset` can also be expressed as `intersection fileset (fileFilter pred path)` without loss of functionality. - This is furthermore pointed out in the new error message when a file set is passed
Diffstat (limited to 'lib/fileset/default.nix')
-rw-r--r-- | lib/fileset/default.nix | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/fileset/default.nix b/lib/fileset/default.nix index d90c770633d83..81be1af9d8a1a 100644 --- a/lib/fileset/default.nix +++ b/lib/fileset/default.nix @@ -366,7 +366,7 @@ in { type :: String, ... } -> Bool) - -> FileSet + -> Path -> FileSet Example: @@ -397,14 +397,24 @@ in { Other attributes may be added in the future. */ predicate: - # The file set to filter based on the predicate function - fileset: + # The path whose files to filter + path: if ! isFunction predicate then throw '' lib.fileset.fileFilter: First argument is of type ${typeOf predicate}, but it should be a function instead.'' + else if ! isPath path then + if path._type or "" == "fileset" then + throw '' + lib.fileset.fileFilter: Second argument is a file set, but it should be a path instead. + If you need to filter files in a file set, use `intersection fileset (fileFilter pred ./.)` instead.'' + else + throw '' + lib.fileset.fileFilter: Second argument is of type ${typeOf path}, but it should be a path instead.'' + else if ! pathExists path then + throw '' + lib.fileset.fileFilter: Second argument (${toString path}) is a path that does not exist.'' else - _fileFilter predicate - (_coerce "lib.fileset.fileFilter: Second argument" fileset); + _fileFilter predicate path; /* The file set containing all files that are in both of two given file sets. |