Flakes support seemingly broken
I've tried following the Flakes support section, but the resulting setup is broken in two ways:
-
nix flake checkprints the diff necessary to satisfy the formatters, but doesn't actually apply them. -
nix develop(after adirenv deny) does not set up pre-commit hooks, sogit commitskips all of them.
nix flake check prints the diff necessary to satisfy the formatters, but doesn't actually apply them.
This is expected behaviour though, no? For nix build and nix flake check, flakes require the src to be copied over to the store. So the diff is being applied during the build, just not to your local copy. If you want the changes to be applied locally, run pre-commit run -a inside nix develop.
nix develop (after a direnv deny) does not set up pre-commit hooks, so git commit skips all of them.
Do you have some more detailed steps I can follow to reproduce this?
nix flake check prints the diff necessary to satisfy the formatters, but doesn't actually apply them.
This is expected behaviour though, no? For
nix buildandnix flake check, flakes require thesrcto be copied over to the store. So the diff is being applied during the build, just not to your local copy. If you want the changes to be applied locally, runpre-commit run -ainsidenix develop.
I might've missed it, but I wish this sort of giant caveat was spelled out before trying it out. I thought git-hooks.nix would just create a pre-commit "bundle" which would then be auto-referenced from Git hooks, to be run against the current state of the code.
nix develop (after a direnv deny) does not set up pre-commit hooks, so git commit skips all of them.
Do you have some more detailed steps I can follow to reproduce this?
- Clone repo above
- Check out commit above
- Run
nix develop - Try to
git commitsomething
I wish this sort of giant caveat was spelled out before trying it out. I thought git-hooks.nix would just create a pre-commit "bundle" which would then be auto-referenced from Git hooks, to be run against the current state of the code.
Yeah, we should say that nix flake check can only validate formatting, not fix.
This might be possible to achieve with nix fmt. You can set formatters in the flake and then point it to a bash script that runs pre-commit run -a. PRs very welcome on this front.
Indeed, nix flake checks run in a sandbox and therefore cannot alter the contents of your repository. This is not specific to git-hooks.nix but of anything you put in a nix flake check. The documentation of flakes support does say “to run the all the hooks on CI”, but can maybe be made clearer.
You can however:
- Go the
nix fmtroute. This would be very nice, I think, but requires quite a bit of code. - Expose a
nix run .#pre-commitutility of some kind. - Expose the pre-commit configuration in your devShell, which will set up the pre-commit, but also allow you to run
pre-commit run -a.
I personally have been using the last option and been very happy with it.
Check the shellHook env variable, if it's not set you might have started the wrong dev shell. Don't ask how I know this and how long it took to figure out..
It should be something like this:
env | grep shellHook
shellHook=export PATH=/nix/store/v0sf67x7sw6pg277amhgf3j84m60wrqn-pre-commit-4.2.0/bin:$PATH
I've added more examples to the README, explaining how to configure and use nix develop and nix fmt, as well as when to avoid nix flake check.