plausible: adapt update script to new nix-prefetch-github

Take the opportunity to switch to SRI hashes.
This commit is contained in:
Theodore Ni 2023-07-07 23:03:08 -07:00
parent 205803c1ee
commit 551db1309c
No known key found for this signature in database
GPG Key ID: 48B67583BDDD4474
2 changed files with 7 additions and 7 deletions

View File

@ -18,7 +18,7 @@ let
owner = "plausible";
repo = "analytics";
rev = "v${version}";
sha256 = "1ckw5cd4z96jkjhmzjq7k3kzjj7bvj38i5xq9r43cz0sn7w3470k";
hash = "sha256-Exwy+LEafDZITriXiIbc60j555gHy1+hnNKkTxorfLI=";
};
# TODO consider using `mix2nix` as soon as it supports git dependencies.

View File

@ -33,18 +33,18 @@ echo "$package_json" \
> $dir/package.json
tarball_meta="$(nix-prefetch-github plausible analytics --rev "$latest")"
tarball_hash="$(nix to-base32 sha256-$(jq -r '.sha256' <<< "$tarball_meta"))"
tarball_hash="$(jq -r '.hash' <<< "$tarball_meta")"
tarball_path="$(nix-build -E 'with import ./. {}; { p }: fetchFromGitHub (builtins.fromJSON p)' --argstr p "$tarball_meta")"
fake_hash="$(nix-instantiate --eval -A lib.fakeSha256 | xargs echo)"
fake_hash="$(nix-instantiate --eval -A lib.fakeHash | xargs echo)"
sed -i "$dir/default.nix" \
-e 's,version = ".*",version = "'"$nix_version"'",' \
-e '/^ src = fetchFromGitHub/,+4{;s/sha256 = "\(.*\)"/sha256 = "'"$tarball_hash"'"/}' \
-e '/^ mixFodDeps =/,+3{;s/sha256 = "\(.*\)"/sha256 = "'"$fake_hash"'"/}'
-e '/^ src = fetchFromGitHub/,+4{;s#hash = "\(.*\)"#hash = "'"$tarball_hash"'"#}' \
-e '/^ mixFodDeps =/,+3{;s#hash = "\(.*\)"#hash = "'"$fake_hash"'"#}'
mix_hash="$(nix to-base32 $(nix-build -A plausible.mixFodDeps 2>&1 | tail -n3 | grep 'got:' | cut -d: -f2- | xargs echo || true))"
mix_hash="$(nix-build -A plausible.mixFodDeps 2>&1 | tail -n3 | grep 'got:' | cut -d: -f2- | xargs echo || true)"
sed -i "$dir/default.nix" -e '/^ mixFodDeps =/,+3{;s/sha256 = "\(.*\)"/sha256 = "'"$mix_hash"'"/}'
sed -i "$dir/default.nix" -e '/^ mixFodDeps =/,+3{;s#hash = "\(.*\)"#hash = "'"$mix_hash"'"#}'
tmp_setup_dir="$(mktemp -d)"
trap "rm -rf $tmp_setup_dir" EXIT