nix-filter icon indicating copy to clipboard operation
nix-filter copied to clipboard

can this be composed with gitignore based filter?

Open adrian-gierakowski opened this issue 3 years ago • 3 comments

I'd like to have an explicit whitelist specified with nix-filter combined with a blacklist based on .gitignore. Can I compose nix-filter somehow with, for example: https://github.com/hercules-ci/gitignore.nix? Thanks!

adrian-gierakowski avatar Feb 02 '22 11:02 adrian-gierakowski

Bump

adrian-gierakowski avatar Aug 09 '22 08:08 adrian-gierakowski

It would take a few days of work to assess and come up with a composable design properly. It's not something I planned to address, unless it comes up as a need in our consulting work.

zimbatm avatar Aug 09 '22 09:08 zimbatm

I recently developed a safer and easier-to-use abstraction for source filtering in a PR to Nixpkgs, please take a look, try it out, and give feedback! https://discourse.nixos.org/t/easy-source-filtering-with-file-sets/29117

Along with basic combinators allowing you to add/remove files, it also comes with a lib.fileset.fromSource function, which can turn lib.source-based values, such as pkgs.nix-gitignore or gitignore.nix into a value that can be composed easily, like this:

let
  fs = lib.fileset;
in
# Remove all `./tests` files from non-gitignored files
fs.difference
  (fs.fromSource (gitignoreSource ./.))
  ./tests

This fixes the problem in this issue!

infinisil avatar Jun 19 '23 18:06 infinisil