about summary refs log tree commit diff
diff options
context:
space:
mode:
-rwxr-xr-xpkgs/development/compilers/graalvm/community-edition/update.sh18
1 files 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 fb1036cf88707..68583d7d5fd78 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}}\";"