gitignore.nix
1 min read
This goal of this project lets you include local sources in your Nix projects, while taking gitignore files into account.

With Flakes
Although Flakes usually process sources within the flake using the git fetcher, which takes care of ignoring in its own peculiar way, you can use gitignore.nix to filter sources outside of a flake. You can load flake-based expressions via builtins.getFlake (toString ./.) for example or via flake-compat.

nix
# // flake.nix
{
inputs.gitignore = {
url = "github:hercules-ci/gitignore.nix";
# Use the same nixpkgs
inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, /* other, inputs, */ gitignore }:
let
inherit (gitignore.lib) gitignoreSource;
in {
packages.x86_64.hello = mkDerivation {
name = "hello";
src = gitignoreSource ./vendored/hello;
};
};
}

Usage

nix
mkDerivation {
name = "hello";
src = gitignoreSource ./vendored/hello;
}

gitignoreSource :: path -> path

Returns result of cleanSourceWith, usable as a path but also composable.

gitignoreFilter :: path -> (path -> type -> bool)

f = gitignoreFilter path