Skip to content

Commit

Permalink
Update docs on source filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
ipetkov committed Nov 8, 2024
1 parent 630b41f commit 487924a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* [Workspace with Trunk](./examples/trunk-workspace.md)
* [End-to-End Testing](./examples/end-to-end-testing.md)
* [Building with SQLx](./examples/sqlx.md)
* [Source filtering](./source-filtering.md)
* [Source filtering and filesets](./source-filtering.md)
* [Local development](./local_development.md)
* [Custom cargo commands](./custom_cargo_commands.md)
* [Customizing builds](./customizing_builds.md)
Expand Down
27 changes: 27 additions & 0 deletions docs/source-filtering.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,30 @@ craneLib.buildPackage {
};
}
```

## Fileset filtering

A more composable alternative to source filtering is using [filesets]:

```nix
let
unfilteredRoot = ./.; # The original, unfiltered source
src = lib.fileset.toSource {
root = unfilteredRoot;
fileset = lib.fileset.unions [
# Default files from crane (Rust and cargo files)
(craneLib.fileset.commonCargoSources unfilteredRoot)
# Also keep any markdown files
(lib.fileset.fileFilter (file: file.hasExt == "md") unfilteredRoot)
# Example of a folder for images, icons, etc
(lib.fileset.maybeMissing ./assets)
];
};
in
craneLib.buildPackage {
# other attributes omitted
inherit src;
}
```

[filesets]: https://nixos.org/manual/nixpkgs/unstable/#sec-functions-library-fileset

0 comments on commit 487924a

Please sign in to comment.