git-hooks.nix icon indicating copy to clipboard operation
git-hooks.nix copied to clipboard

Add docs, examples for overriding provided hooks

Open domenkozar opened this issue 6 years ago • 9 comments

Something like:

nix-pre-commit-hooks.run {
  src = gitignoreSource ./.;
  hooks = ["shellcheck"];
}

domenkozar avatar Aug 16 '19 15:08 domenkozar

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)

roberth avatar Aug 16 '19 20:08 roberth

Even better: generate a YAML from with builtins.toJSON. Best: use the module system.

roberth avatar Aug 16 '19 21:08 roberth

If this is about download size, I wrote a thing https://github.com/roberth/nix-lazy-env

roberth avatar Sep 08 '19 15:09 roberth

Nice! Yes, partially it's about the download size and partially it's for providing additional hooks.

domenkozar avatar Sep 09 '19 07:09 domenkozar

This seems nice and simple: https://github.com/kampka/pre-commit-hooks

domenkozar avatar Sep 09 '19 17:09 domenkozar

Let's leave this one open as it needs some examples in the docs.

domenkozar avatar Oct 02 '19 09:10 domenkozar

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?

timokau avatar Mar 20 '20 21:03 timokau

I'll let that @roberth answer, I was also more for simple design of attrsets and defaults.

domenkozar avatar Mar 20 '20 21:03 domenkozar

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

roberth avatar Mar 20 '20 21:03 roberth

https://github.com/cachix/pre-commit-hooks.nix#custom-hooks is now there

domenkozar avatar Oct 08 '23 13:10 domenkozar