cachix/git-hooks.nix

Per-hook flake output `check` derivations

gekoke opened this issue · 1 comments

It would be nice if each hook could be built as a separate derivation. Currently, only one flake check output with the name pre-commit is produced.

If the hooks could be split into separate derivations, one could:

Is this something that is possible to implement? I understand there is the upstream dependency on pre-commit-hooks that might come into play here.

I suppose so. One thing to keep in mind is that there'll be a setup cost to pay for each check, not to mention the cost of launching a whole new job for each check.

run =
runCommand "pre-commit-run" { buildInputs = [ git ]; } ''
set +e
HOME=$PWD
# Use `chmod +w` instead of `cp --no-preserve=mode` to be able to write and to
# preserve the executable bit at the same time
cp -R ${cfg.rootSrc} src
chmod -R +w src
ln -fs ${configFile} src/.pre-commit-config.yaml
cd src
rm -rf .git
git init -q
git add .
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git commit -m "init" -q
if [[ ${toString (compare install_stages [ "manual" ])} -eq 0 ]]
then
echo "Running: $ pre-commit run --hook-stage manual --all-files"
${cfg.package}/bin/pre-commit run --hook-stage manual --all-files
else
echo "Running: $ pre-commit run --all-files"
${cfg.package}/bin/pre-commit run --all-files
fi
exitcode=$?
git --no-pager diff --color
touch $out
[ $? -eq 0 ] && exit $exitcode
'';