-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck.sh
More file actions
executable file
·30 lines (27 loc) · 761 Bytes
/
check.sh
File metadata and controls
executable file
·30 lines (27 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env bash
set -e
# Simple, quick sanity check. Useful as a git pre-commit hook.
CODE=0
while read -r F
do
[[ -n "$DEBUG" ]] && echo "Checking '$F'" 1>&2
nix-instantiate --parse "$F" > /dev/null || CODE=1
if command -v nixfmt > /dev/null
then
if ! nixfmt -w 80 -c "$F"
then
CODE=1
if [[ -n "$REFORMAT" ]]
then
nixfmt -w 80 "$F"
else
echo "(Set REFORMAT=1 to auto-format)" 1>&2
fi
fi
fi
done < <(find . -name "*.nix")
# Fail if checks don't pass
EXPR='(import ./nix).nix-config-check || abort "Checks failed"'
nix-instantiate --show-trace --read-write-mode --eval -E "$EXPR" > /dev/null ||
CODE=1
exit "$CODE"