Skip to content

Commit a30bbdb

Browse files
committed
fix the update-nix script
1 parent 7fe6254 commit a30bbdb

File tree

3 files changed

+65
-37
lines changed

3 files changed

+65
-37
lines changed

nix/mantis.nix

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,10 @@ in sbt.mkDerivation rec {
6060
})
6161
];
6262

63-
#patchPhase = lib.optionalString (libsonic != null) ''
64-
# rm -rf src/main/resources
65-
# cp -r ${libsonic}/lib src/main/resources
66-
#'';
67-
6863
# This sha represents the change dependencies of mantis.
69-
# Update this sha whenever you change the dependencies
70-
depsSha256 = "0n7vv4k73cxjwg40qggr7gnkkg7vn8a179sf0wxnz3absj1700jj";
64+
# Update this sha whenever you change the dependencies using the
65+
# update-nix.sh script
66+
depsSha256 = "sha256-csNBHVOC2bNSOjLjWleiVeS5ts3qFS7V8DxBv2nVDqE=";
7167

7268
# this is the command used to to create the fixed-output-derivation
7369
depsWarmupCommand = "PROTOC_CACHE=.nix/protoc-cache; HOME=$TMPDIR; PATH=${PATH}:$PATH; sbt clean; sbt compile --debug";

nix/overlay.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ rev: final: prev: {
1010
};
1111
};
1212

13+
mantis-hash = { ref, rev }:
14+
(final.callPackage ./mantis.nix {
15+
src = builtins.fetchGit {
16+
url = "https://github.com/input-output-hk/mantis";
17+
inherit rev ref;
18+
submodules = true;
19+
};
20+
}).overrideAttrs (_: {
21+
outputHash = "sha256-0000000000000000000000000000000000000000000=";
22+
outputHashMode = "recursive";
23+
});
24+
1325
writeBashChecked = final.writers.makeScriptWriter {
1426
interpreter = "${final.bashInteractive}/bin/bash";
1527
check = final.writers.writeBash "shellcheck-check" ''

update-nix.sh

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,70 @@
11
#!/usr/bin/env bash
22

3-
set -e
3+
set -euo pipefail
44

5-
name=$(basename $0)
5+
name=$(basename "$0")
66

77
usage() {
8-
echo "$name - Tool used to validate and update the sbt nix build"
9-
echo ""
10-
echo "USAGE:"
11-
echo " $name [--check]"
12-
echo ""
13-
echo "OPTIONS:"
14-
echo -e " --check\t Check whether ./nix/pkgs/mantis.nix is up-to-date"
8+
echo "$name - Tool used to validate and update the sbt nix build"
9+
echo ""
10+
echo "USAGE:"
11+
echo " $name [--check]"
12+
echo ""
13+
echo "OPTIONS:"
14+
echo -e " --check\t Check whether ./nix/mantis.nix is up-to-date"
1515
}
1616

17-
if [ "$1" == "-h" -o "$1" == "--help" ]; then
18-
usage
19-
exit 1
17+
if [ "${1:-}" == "-h" ] || [ "${1:-}" == "--help" ]; then
18+
usage
19+
exit 1
2020
fi
2121

2222
echo "Determining new sha for sbt build, this can take several minutes to do a 'sbt compile'"
2323

24-
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 )
24+
branch="$(git rev-parse --abbrev-ref HEAD)"
25+
revision="$(git rev-parse HEAD)"
26+
27+
output="$(
28+
nix build \
29+
--impure \
30+
--expr "
31+
(builtins.getFlake (toString ./.)).legacyPackages.x86_64-linux.mantis-hash {
32+
ref = \"${branch}\";
33+
rev = \"${revision}\";
34+
}
35+
" 2>&1 || true
36+
)"
37+
38+
NEW_SHA=$(
39+
echo "$output" \
40+
| awk '/^\s+got: / { print $2 }'
41+
)
42+
43+
if [ -z "$NEW_SHA" ]; then
44+
echo "$output"
45+
echo "calculating hash failed!"
46+
exit 1
47+
fi
2548

2649
echo "Calculated sha: $NEW_SHA"
2750

2851
update_sha() {
29-
echo "Updating sha in ./nix/pkgs/mantis.nix"
30-
sed -r -i -e "s|depsSha256 = \"[^\"]+\";|depsSha256 = \"${NEW_SHA}\";|" ./nix/pkgs/mantis.nix
31-
echo "./nix/pkgs/mantis.nix has been updated"
52+
echo "Updating sha in ./nix/mantis.nix"
53+
sed -r -i -e "s|depsSha256 = \"[^\"]+\";|depsSha256 = \"${NEW_SHA}\";|" ./nix/mantis.nix
54+
echo "./nix/mantis.nix has been updated"
3255
}
3356

34-
if [ $# == 1 -o "$1" == "--check" ]; then
35-
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 )
36-
if [ "$current_sha" == "$NEW_SHA" ]; then
37-
echo "./nix/pkgs/mantis.nix is up-to-date"
38-
exit 0
39-
else
40-
echo "wanted: $NEW_SHA"
41-
echo " got: $current_sha"
42-
update_sha
43-
exit 1
44-
fi
57+
if [ $# == 1 ] || [ "${1:-}" == "--check" ]; then
58+
current_sha=$(grep depsSha256 ./nix/mantis.nix | sed 's/\s*depsSha256\s*=\s*//g' | sed -e 's/"//g' -e 's/;//g' | xargs nix-hash --to-base32 --type sha256 )
59+
if [ "$current_sha" == "$NEW_SHA" ]; then
60+
echo "./nix/mantis.nix is up-to-date"
61+
exit 0
62+
else
63+
echo "wanted: $NEW_SHA"
64+
echo " got: $current_sha"
65+
update_sha
66+
exit 1
67+
fi
4568
fi
4669

4770
update_sha
48-
49-
50-

0 commit comments

Comments
 (0)