From 1e39bda357bedf5b22fa31baab1f6c16d07f65b8 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Wed, 15 Feb 2023 21:07:41 +0000 Subject: [PATCH] graalvm*-ce: improve update.sh script --- .../graalvm/community-edition/update.sh | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pkgs/development/compilers/graalvm/community-edition/update.sh b/pkgs/development/compilers/graalvm/community-edition/update.sh index fb1036cf8870..68583d7d5fd7 100755 --- a/pkgs/development/compilers/graalvm/community-edition/update.sh +++ b/pkgs/development/compilers/graalvm/community-edition/update.sh @@ -6,6 +6,8 @@ set -eou pipefail cd "$(dirname "${BASH_SOURCE[0]}")" tmpfile="$(mktemp --suffix=.nix)" +trap 'rm -rf "$tmpfile"' EXIT + info() { echo "[INFO] $*"; } echo_file() { echo "$@" >> "$tmpfile"; } @@ -59,7 +61,7 @@ readonly platforms=( "17-darwin-amd64" ) -info "Generating hashes.nix file for 'graalvm-ce' $new_version. This will take a while..." +info "Generating '$hashes_nix' file for 'graalvm-ce' $new_version. This will take a while..." # Indentation of `echo_file` function is on purpose to make it easier to visualize the output echo_file "# Generated by $0 script" @@ -68,14 +70,16 @@ for product in "${!products_urls[@]}"; do url="${products_urls["${product}"]}" echo_file " \"$product\" = {" for platform in "${platforms[@]}"; do - # Reuse cache as long the version is the same - if [[ "$current_version" == "$new_version" ]]; then - previous_hash="$(nix-instantiate --eval "$hashes_nix" -A "$product.$platform.sha256" --json | jq -r || true)" + args=("${url//@platform@/$platform}") + # Get current hashes to skip derivations already in /nix/store to reuse cache when the version is the same + # e.g.: when adding a new product and running this script with FORCE=1 + if [[ "$current_version" == "$new_version" ]] && \ + previous_hash="$(nix-instantiate --eval "$hashes_nix" -A "$product.$platform.sha256" --json | jq -r)"; then + args+=("$previous_hash" "--type" "sha256") else - previous_hash="" + info "Hash in '$product' for '$platform' not found. Re-downloading it..." fi - # Lack of quoting in $previous_hash is proposital - if hash="$(nix-prefetch-url "${url//@platform@/$platform}" $previous_hash)"; then + if hash="$(nix-prefetch-url "${args[@]}")"; then echo_file " \"$platform\" = {" echo_file " sha256 = \"$hash\";" echo_file " url = \"${url//@platform@/${platform}}\";"