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

`pass_filenames` broken when used with flakes

Open DavHau opened this issue 3 years ago • 2 comments
trafficstars

I'm currently trying to set up a hook for a flake to run treefmt only on changed files. With flakes nix always removes the .git directory before even starting the evaluation. Therefore there is no chance for the hook to learn about which files have been changed.

One solution could be to support nix run based checks.

DavHau avatar Mar 07 '22 05:03 DavHau

the pre commit hook when installed correctly runs on the git repo on changed/added files if your hook runs on a store path, the setup is completely wrong, it must run on the real path

RonnyPfannschmidt avatar Aug 17 '23 11:08 RonnyPfannschmidt

  • The check derivation ("run") is meant for CI to guarantee a complete check.
  • For your commit cycle you can use the generated config file via the shell that's available, which is even faster because the config file is generated only once when you start your dev shell.

In my view that covers all use cases.

Something based on nix run would be a slower version of what the actual pre-commit command and the actual hooks do for you. The only benefit I see to this is that if you always regenerate the config file, it can't go stale, but stale config isn't a problem because you the guaranteed complete and up to date check in CI.

I guess this needs to be explained in docs?

roberth avatar Aug 17 '23 11:08 roberth