Skip to content

Commit

Permalink
Make parent dir available in fileset.fileFilter
Browse files Browse the repository at this point in the history
Currently, fileFilter only allows filtering based based on a files base
name + file type.

This is a bit limiting if you want to include files based on the name of
the directory they reside in.

I bumped in to this when using fileFilter to make a minimal set of files
to make Cargo happy in a Rust workspace - specifically, I needed to pull
in any `.rs` file that lived under a `bin/`, `examples/`, or `benches/`
folder before Cargo would stop complaining. (Note that I am trying to
avoid pulling in all rust files - I'm working in a large Rust workspace
but trying to package a single small member of the workspace).

```
  • Loading branch information
andrewhamon committed Apr 23, 2024
1 parent 572af61 commit 8c72702
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/fileset/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,8 @@ in {
- `name` (String): The name of the file
- `dir` (Path): The path of the directory containing the file.
- `type` (String, one of `"regular"`, `"symlink"` or `"unknown"`): The type of the file.
This matches result of calling [`builtins.readFileType`](https://nixos.org/manual/nix/stable/language/builtins.html#builtins-readFileType) on the file's path.
Expand Down
8 changes: 4 additions & 4 deletions lib/fileset/internal.nix
Original file line number Diff line number Diff line change
Expand Up @@ -825,11 +825,11 @@ rec {
_fileFilter = predicate: root:
let
# Check the predicate for a single file
# Type: String -> String -> filesetTree
fromFile = name: type:
# Type: Path -> String -> String -> filesetTree
fromFile = dir: name: type:
if
predicate {
inherit name type;
inherit dir name type;
hasExt = ext: hasSuffix ".${ext}" name;

# To ensure forwards compatibility with more arguments being added in the future,
Expand All @@ -848,7 +848,7 @@ rec {
if type == "directory" then
fromDir (path + "/${name}")
else
fromFile name type
fromFile path name type
) (readDir path);

rootType = pathType root;
Expand Down

0 comments on commit 8c72702

Please sign in to comment.