Skip to content

Commit

Permalink
rely on depsSha256 instead of a hack
Browse files Browse the repository at this point in the history
  • Loading branch information
manveru committed Mar 31, 2021
1 parent 6bf0acf commit 7cbb446
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
15 changes: 13 additions & 2 deletions nix/mantis.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
, substituteAll
, writeBashBinChecked
, mantis-extvm-pb
, depsSha256
}:

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

# this is the command used to to create the fixed-output-derivation
depsWarmupCommand = "PROTOC_CACHE=.nix/protoc-cache; HOME=$TMPDIR; PATH=${PATH}:$PATH; sbt clean; sbt compile --debug";
depsWarmupCommand = ''
export PROTOC_CACHE=.nix/protoc-cache
export HOME="$TMPDIR"
export PATH="${PATH}:$PATH"
mkdir -p src/main/protobuf/extvm
cp ${mantis-extvm-pb}/msg.proto src/main/protobuf/extvm/msg.proto
sbt clean
sbt compile --debug
'';

installPhase = ''
sbt stage
Expand Down
16 changes: 5 additions & 11 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,18 @@ rev: final: prev: {

mantis = final.callPackage ./mantis.nix {
src = ../.;
depsSha256 = "sha256-csNBHVOC2bNSOjLjWleiVeS5ts3qFS7V8DxBv2nVDqE=";
};

mantis-hash = { ref, rev }:
(final.callPackage ./mantis.nix {
src = builtins.fetchGit {
url = "https://github.com/input-output-hk/mantis";
inherit rev ref;
};
}).overrideAttrs (_: {
outputHash = "sha256-0000000000000000000000000000000000000000000=";
outputHashMode = "recursive";
});
mantis-hash = final.mantis.override {
depsSha256 = "sha256-0000000000000000000000000000000000000000000=";
};

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

writeBashChecked = final.writers.makeScriptWriter {
Expand Down
35 changes: 14 additions & 21 deletions update-nix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,39 @@ fi

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

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

output="$(
nix build \
--impure \
--expr "
(builtins.getFlake (toString ./.)).legacyPackages.x86_64-linux.mantis-hash {
ref = \"${branch}\";
rev = \"${revision}\";
}
" 2>&1 || true
--expr "(builtins.getFlake (toString ./.)).legacyPackages.x86_64-linux.mantis-hash" \
2>&1 || true
)"

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

if [ -z "$NEW_SHA" ]; then
if [ -z "$new_sha" ]; then
echo "$output"
echo "calculating hash failed!"
exit 1
fi

echo "Calculated sha: $NEW_SHA"
echo "Calculated sha: $new_sha"

update_sha() {
echo "Updating sha in ./nix/mantis.nix"
sed -r -i -e "s|depsSha256 = \"[^\"]+\";|depsSha256 = \"${NEW_SHA}\";|" ./nix/mantis.nix
echo "./nix/mantis.nix has been updated"
echo "Updating sha in ./nix/overlay.nix"
sed -i "s|depsSha256 = \"$current_sha\";|depsSha256 = \"$new_sha\";|" nix/overlay.nix
echo "./nix/overlay.nix has been updated"
}

if [ $# == 1 ] || [ "${1:-}" == "--check" ]; then
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 )
if [ "$current_sha" == "$NEW_SHA" ]; then
echo "./nix/mantis.nix is up-to-date"
current_sha=$(nix eval --raw '.#mantis.deps.outputHash')
if [ "$current_sha" == "$new_sha" ]; then
echo "./nix/overlay.nix is up-to-date"
exit 0
else
echo "wanted: $NEW_SHA"
echo "wanted: $new_sha"
echo " got: $current_sha"
update_sha
exit 1
Expand Down

0 comments on commit 7cbb446

Please sign in to comment.