gitignore.nix
gitignore.nix copied to clipboard
A filter that includes .git
Since I needed this myself, here is a gitignore filter that includes the .git
directory itself (which is often needed for running git
commands):
{ lib, gitignoreFilter }: path:
let
ignoreFilter = gitignoreFilter path;
dotGit = toString path + "/.git";
in lib.cleanSourceWith {
src = path;
filter = path: type: lib.hasPrefix dotGit path || ignoreFilter path type;
}
It might be worth adding a filter with this functionality to this library
I think we can generalize this to a function that isn't specific to gitignore.nix
.
Something like unionFilterAndSource: (origSrc -> path -> type -> bool) -> src -> src
.
It can even memoize your dotGit
by let
binding the partially applied filter function.
I guess combining filters with cleanSourceWith
is like an AND statement, whereas this would add OR's, so the boolean logic equivalent is Disjunctive normal form. Maybe this can be a guiding principle in a generalized interface, e.g.
filterDNF [
[ (only ".git") ]
[ gitignore (not "foo" ) ]
]
For a filter that includes all of .git
unioned with all files that pass both the gitignore
and are not in the folder foo
(or: .git OR (gitignore AND (NOT "foo"))
)
Doesn't have to be normal form though and my thinking was that set terminology is more natural here, because at this level we're thinking about sets of files rather than bools.
See https://github.com/NixOS/nixpkgs/pull/112083
that set terminology is more natural here, because at this level we're thinking about sets of files rather than bools.
This is a good first intuition but not entirely accurate as illustrated by the example where the union of a
and b/c
necessarily includes b
. This is just a theoretical observation at this point. https://github.com/NixOS/nixpkgs/pull/112083 takes care of it.
my thinking was that set terminology is more natural here, because at this level we're thinking about sets of files rather than bools.
Just happen to come across this issue again, and indeed, I now also think of it as sets of files! :laughing: https://github.com/NixOS/nixpkgs/pull/222981