Skip to content

Commit 7cbb446

Browse files
committed
rely on depsSha256 instead of a hack
1 parent 6bf0acf commit 7cbb446

File tree

3 files changed

+32
-34
lines changed

3 files changed

+32
-34
lines changed

nix/mantis.nix

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
, substituteAll
1515
, writeBashBinChecked
1616
, mantis-extvm-pb
17+
, depsSha256
1718
}:
1819

1920
let
@@ -66,10 +67,20 @@ in sbt.mkDerivation rec {
6667
# This sha represents the change dependencies of mantis.
6768
# Update this sha whenever you change the dependencies using the
6869
# update-nix.sh script
69-
depsSha256 = "sha256-csNBHVOC2bNSOjLjWleiVeS5ts3qFS7V8DxBv2nVDqE=";
70+
inherit depsSha256;
7071

7172
# this is the command used to to create the fixed-output-derivation
72-
depsWarmupCommand = "PROTOC_CACHE=.nix/protoc-cache; HOME=$TMPDIR; PATH=${PATH}:$PATH; sbt clean; sbt compile --debug";
73+
depsWarmupCommand = ''
74+
export PROTOC_CACHE=.nix/protoc-cache
75+
export HOME="$TMPDIR"
76+
export PATH="${PATH}:$PATH"
77+
78+
mkdir -p src/main/protobuf/extvm
79+
cp ${mantis-extvm-pb}/msg.proto src/main/protobuf/extvm/msg.proto
80+
81+
sbt clean
82+
sbt compile --debug
83+
'';
7384

7485
installPhase = ''
7586
sbt stage

nix/overlay.nix

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,18 @@ rev: final: prev: {
33

44
mantis = final.callPackage ./mantis.nix {
55
src = ../.;
6+
depsSha256 = "sha256-csNBHVOC2bNSOjLjWleiVeS5ts3qFS7V8DxBv2nVDqE=";
67
};
78

8-
mantis-hash = { ref, rev }:
9-
(final.callPackage ./mantis.nix {
10-
src = builtins.fetchGit {
11-
url = "https://github.com/input-output-hk/mantis";
12-
inherit rev ref;
13-
};
14-
}).overrideAttrs (_: {
15-
outputHash = "sha256-0000000000000000000000000000000000000000000=";
16-
outputHashMode = "recursive";
17-
});
9+
mantis-hash = final.mantis.override {
10+
depsSha256 = "sha256-0000000000000000000000000000000000000000000=";
11+
};
1812

1913
# Last change to this was in 2018, so to avoid submodules we just clone
2014
# ourselves instead.
2115
mantis-extvm-pb = builtins.fetchGit {
2216
url = "https://github.com/input-output-hk/mantis-extvm-pb";
23-
rev = "53eb31f3c59f7200994915b834e626bd292df7ed";
17+
rev = "53eb31f3c59f7200994915b834e626bd292df7ed";
2418
};
2519

2620
writeBashChecked = final.writers.makeScriptWriter {

update-nix.sh

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,46 +21,39 @@ fi
2121

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

24-
branch="$(git rev-parse --abbrev-ref HEAD)"
25-
revision="$(git rev-parse HEAD)"
24+
current_sha=$(nix eval --raw '.#mantis.deps.outputHash')
2625

2726
output="$(
2827
nix build \
2928
--impure \
30-
--expr "
31-
(builtins.getFlake (toString ./.)).legacyPackages.x86_64-linux.mantis-hash {
32-
ref = \"${branch}\";
33-
rev = \"${revision}\";
34-
}
35-
" 2>&1 || true
29+
--expr "(builtins.getFlake (toString ./.)).legacyPackages.x86_64-linux.mantis-hash" \
30+
2>&1 || true
3631
)"
3732

38-
NEW_SHA=$(
39-
echo "$output" \
40-
| awk '/^\s+got: / { print $2 }'
41-
)
33+
new_sha="$(echo "$output" | awk '/^\s*got: / { print $2 }')"
34+
current_sha=$(nix eval --raw '.#mantis.deps.outputHash')
4235

43-
if [ -z "$NEW_SHA" ]; then
36+
if [ -z "$new_sha" ]; then
4437
echo "$output"
4538
echo "calculating hash failed!"
4639
exit 1
4740
fi
4841

49-
echo "Calculated sha: $NEW_SHA"
42+
echo "Calculated sha: $new_sha"
5043

5144
update_sha() {
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"
45+
echo "Updating sha in ./nix/overlay.nix"
46+
sed -i "s|depsSha256 = \"$current_sha\";|depsSha256 = \"$new_sha\";|" nix/overlay.nix
47+
echo "./nix/overlay.nix has been updated"
5548
}
5649

5750
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"
51+
current_sha=$(nix eval --raw '.#mantis.deps.outputHash')
52+
if [ "$current_sha" == "$new_sha" ]; then
53+
echo "./nix/overlay.nix is up-to-date"
6154
exit 0
6255
else
63-
echo "wanted: $NEW_SHA"
56+
echo "wanted: $new_sha"
6457
echo " got: $current_sha"
6558
update_sha
6659
exit 1

0 commit comments

Comments
 (0)