hooks/pre-commit: make sure to use nix-fmt from flake

This commit is contained in:
Kevin Baensch 2025-03-21 23:51:29 +01:00
parent bd04542478
commit d8f29e12b5
Signed by: derped
GPG key ID: C0F1D326C7626543

View file

@ -1,4 +1,5 @@
#!/usr/bin/env bash
set -e
printf "%s\n" "Running nixfmt pre-commit hook.";
if ! which grep >/dev/null; then
@ -6,15 +7,13 @@ if ! which grep >/dev/null; then
exit 1;
fi;
if ! which nixfmt >/dev/null; then
printf '%s\n' "ERR: nixfmt not found.";
exit 1;
fi;
ARCH="$(uname -m)-$(uname | tr "[:upper:]" "[:lower:]")"
NIX_FMT="$(nix build --no-link --print-out-paths .#formatter."${ARCH}")"
RESULT=0;
for file in $(git diff --name-only --cached); do
if grep -q "\.nix$" <<< "${file}"; then
nixfmt -c <<< "$(git cat-file blob :"${file}")" 2> >(sed "s|<stdin>|${file}|");
"${NIX_FMT}"/bin/nixfmt -c <<< "$(git cat-file blob :"${file}")" 2> >(sed "s|<stdin>|${file}|");
RESULT=$(( RESULT || $? ));
fi;
done;