git-hooks.nix
git-hooks.nix copied to clipboard
Add docs, examples for overriding provided hooks
Something like:
nix-pre-commit-hooks.run {
src = gitignoreSource ./.;
hooks = ["shellcheck"];
}
I'd be perfectly happy to require the YAML to be JSON and DRY it with builtins.fromJSON.
(as an alternative, not everyone likes JSON)
Even better: generate a YAML from with builtins.toJSON. Best: use the module system.
If this is about download size, I wrote a thing https://github.com/roberth/nix-lazy-env
Nice! Yes, partially it's about the download size and partially it's for providing additional hooks.
This seems nice and simple: https://github.com/kampka/pre-commit-hooks
Let's leave this one open as it needs some examples in the docs.
For what it's worth, I came up with this config to run the black python code formatter:
let
nix-pre-commit-hooks = import (builtins.fetchTarball "https://github.com/cachix/pre-commit-hooks.nix/tarball/master");
pkgs = import <nixpkgs> {};
in {
pre-commit-check = nix-pre-commit-hooks.run {
src = ./.;
hooks = {
shellcheck.enable = true;
black = {
enable = true;
name = "black";
description = "Format Python files";
entry = "${pkgs.python3.pkgs.black}/bin/black --check";
types = ["python"];
};
};
};
}
That could probably be used as an example. I'm wondering: Why do you use the module-system here? Wouldn't it be easier and more convenient to just use a list of attrsets, with some attrsets pre defined?
I'll let that @roberth answer, I was also more for simple design of attrsets and defaults.
With the module system you get
- type checking, improving error messages
- a framework for documentation
- configurations merging and overrides, so you can have defaults for your team for example
https://github.com/cachix/pre-commit-hooks.nix#custom-hooks is now there