forked from input-output-hk/mantis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-nix.sh
executable file
·50 lines (37 loc) · 1.5 KB
/
update-nix.sh
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
set -e
name=$(basename $0)
usage() {
echo "$name - Tool used to validate and update the sbt nix build"
echo ""
echo "USAGE:"
echo " $name [--check]"
echo ""
echo "OPTIONS:"
echo -e " --check\t Check whether ./nix/pkgs/mantis.nix is up-to-date"
}
if [ "$1" == "-h" -o "$1" == "--help" ]; then
usage
exit 1
fi
echo "Determining new sha for sbt build, this can take several minutes to do a 'sbt compile'"
NEW_SHA=$(nix-build -E 'with import ./. {}; deps.overrideAttrs( _: { outputHash = "0000000000000000000000000000000000000000000000000000"; })' 2>&1 | grep " got: " | head -n 1 | sed -r 's/\s+got:\s+//' | xargs nix-hash --to-base32 --type sha256 )
echo "Calculated sha: $NEW_SHA"
update_sha() {
echo "Updating sha in ./nix/pkgs/mantis.nix"
sed -r -i -e "s|depsSha256 = \"[^\"]+\";|depsSha256 = \"${NEW_SHA}\";|" ./nix/pkgs/mantis.nix
echo "./nix/pkgs/mantis.nix has been updated"
}
if [ $# == 1 -o "$1" == "--check" ]; then
current_sha=$(cat ./nix/pkgs/mantis.nix | grep depsSha256 | sed 's/\s*depsSha256\s*=\s*//g' | sed -e 's/"//g' -e 's/;//g' | xargs nix-hash --to-base32 --type sha256 )
if [ "$current_sha" == "$NEW_SHA" ]; then
echo "./nix/pkgs/mantis.nix is up-to-date"
exit 0
else
echo "wanted: $NEW_SHA"
echo " got: $current_sha"
update_sha
exit 1
fi
fi
update_sha