hooks/pre-commit: make sure to use nix-fmt from flake
This commit is contained in:
parent
bd04542478
commit
d8f29e12b5
1 changed files with 4 additions and 5 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue