Skip to content

Commit

Permalink
Add nix to git hook
Browse files Browse the repository at this point in the history
  • Loading branch information
TheArcaneBrony committed Feb 19, 2024
1 parent 09dacac commit f952ab7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
22 changes: 21 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
#!/usr/bin/env sh
#!nix-shell -i "bash" -p bash prefetch-npm-deps jq nodejs nix-output-monitor
. "$(dirname -- "$0")/_/husky.sh"

npx -y lint-staged
if [ -x "$(/usr/bin/env which nix-shell 2>/dev/null)" ]; then
if [ ! "$HOOK_NIX_SHELL" ]; then
echo "Nix is available, updating nix flake..."
export HOOK_NIX_SHELL=1
nix-shell $0
exit $?
else
# run ./nix-update.sh if package lock has changed and has no unstaged changes
if [ -n "$(git status --porcelain=v1 2>/dev/null | grep -E '^(M| M) package-lock.json')" ]; then
echo "package-lock.json has unstaged changes. Skipping update of nix dependencies."
else
./nix-update.sh || exit $?
fi
fi
else
echo "You do not appear to have nix installed. Skipping update of nix dependencies."
fi

npx -y lint-staged

8 changes: 6 additions & 2 deletions nix-update.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env nix-shell
#!nix-shell -i "bash -x" -p bash prefetch-npm-deps jq
#!nix-shell -i "bash -x" -p bash prefetch-npm-deps jq git nix-output-monitor
nix flake update
DEPS_HASH=`prefetch-npm-deps package-lock.json`
TMPFILE=$(mktemp)
jq '.npm_deps_hash = "'$DEPS_HASH'"' hashes.json > $TMPFILE
mv -- "$TMPFILE" hashes.json
mv -- "$TMPFILE" hashes.json

nom build .# || exit $?
git add hashes.json flake.lock flake.nix

0 comments on commit f952ab7

Please sign in to comment.