about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Flatz <david@upcs.at>2023-10-02 10:51:09 +0200
committerDavid Flatz <david@upcs.at>2024-06-24 12:22:13 +0200
commit73cc1d092b9eb9f6d2eefa6fc94c0a781bf074ba (patch)
treef6720d09b1ab344fa831f9d51750ec33ceff1021
parent4cf0caf146ab1ddc0b3fca61b55c7deebbc79c46 (diff)
androidStudioPackages: iterate over update script
- switch to a working URL to get latest version numbers and parse with jq
- calculate SRI use it to update outputHash
- increase robustness of regexp substutions by using ~ delimiter
-rw-r--r--pkgs/applications/editors/android-studio/common.nix2
-rwxr-xr-xpkgs/applications/editors/android-studio/update.sh36
2 files changed, 19 insertions, 19 deletions
diff --git a/pkgs/applications/editors/android-studio/common.nix b/pkgs/applications/editors/android-studio/common.nix
index 9a247d0bc870b..74f7d3c8f7a47 100644
--- a/pkgs/applications/editors/android-studio/common.nix
+++ b/pkgs/applications/editors/android-studio/common.nix
@@ -257,10 +257,12 @@ let
     passthru = let
       withSdk = androidSdk: mkAndroidStudioWrapper { inherit androidStudio androidSdk; };
     in {
+      inherit version;
       unwrapped = androidStudio;
       full = withSdk androidenv.androidPkgs.androidsdk;
       inherit withSdk;
       sdk = androidSdk;
+      updateScript = [ ./update.sh "${channel}" ];
     };
     meta = {
       description = "Official IDE for Android (${channel} channel)";
diff --git a/pkgs/applications/editors/android-studio/update.sh b/pkgs/applications/editors/android-studio/update.sh
index b443ba164adb9..04efbb3667540 100755
--- a/pkgs/applications/editors/android-studio/update.sh
+++ b/pkgs/applications/editors/android-studio/update.sh
@@ -1,19 +1,24 @@
 #! /usr/bin/env nix-shell
-#! nix-shell -I nixpkgs=./. -i bash -p python3Packages.yq nix-prefetch-scripts
+#! nix-shell -I nixpkgs=./. -i bash -p jq nix-prefetch-scripts
 
 set -euo pipefail
 
 DEFAULT_NIX="$(realpath "./pkgs/applications/editors/android-studio/default.nix")"
-RELEASES_XML="$(curl -v --silent https://raw.githubusercontent.com/JetBrains/intellij-sdk-docs/main/topics/_generated/android_studio_releases.xml 2>/dev/null)"
+RELEASES_JSON="$(curl --silent -L https://jb.gg/android-studio-releases-list.json)"
 
 # Available channels: Release/Patch (stable), Beta, Canary
 getLatest() {
     local attribute="$1"
     local channel="$2"
-    [[ "$channel" = "stable" ]] && channel="release" # Our naming convention is different
-    local result="$(echo "$RELEASES_XML" \
-        | xq -r ".[].item[] | select(.channel == \"${channel^}\") | .${attribute}" \
+    case "$channel" in
+        "stable") local select='.channel == "Release" or .channel == "Patch"' ;;
+        "beta") local select='.channel == "Beta" or .channel == "RC"' ;;
+        *) local select=".channel == \"${channel^}\"" ;;
+    esac
+    local result="$(echo "$RELEASES_JSON" \
+        | jq -r ".content.item[] | select(${select}) | [.version, .${attribute}] | join(\" \")" \
         | sort --version-sort \
+        | cut -d' ' -f 2- \
         | tail -n 1)"
 
     if [[ -n "$result" ]]; then
@@ -27,29 +32,22 @@ getLatest() {
 updateChannel() {
     local channel="$1"
     local latestVersion="$(getLatest "version" "$channel")"
-    if [[ "$channel" = "stable" ]]; then
-        # Sometimes the latest stable version is published under the `patch` channel instead of `release`,
-        # so we need to check if the latest version of the release channel isnt older than the patch channel
-        local latestPatchVersion="$(getLatest "version" "patch")"
-        if [[ "$(nix eval --expr "with import ./default.nix {}; lib.versionOlder \"${latestVersion}\" \"${latestPatchVersion}\"" --impure)" = "true" ]]; then
-            latestVersion="$latestPatchVersion"
-        fi
-    fi
 
-    local localVersion="$(nix eval --raw --file . androidStudioPackages."${channel}".version)"
+    local localVersion="$(nix --extra-experimental-features nix-command eval --raw --file . androidStudioPackages."${channel}".version)"
     if [[ "${latestVersion}" == "${localVersion}" ]]; then
-        echo "$channel is already up to date!"
+        echo "$channel is already up to date at $latestVersion"
         return 0
     fi
     echo "updating $channel from $localVersion to $latestVersion"
 
-    local latestHash="$(nix-prefetch-url --quiet "https://dl.google.com/dl/android/studio/ide-zips/${latestVersion}/android-studio-${latestVersion}-linux.tar.gz")"
-    local localHash="$(nix eval --raw --file . androidStudioPackages."${channel}".unwrapped.src.drvAttrs.outputHash)"
-    sed -i "s/${localHash}/${latestHash}/g" "${DEFAULT_NIX}"
+    local latestHash="$(nix-prefetch-url "https://dl.google.com/dl/android/studio/ide-zips/${latestVersion}/android-studio-${latestVersion}-linux.tar.gz")"
+    local latestSri="$(nix --extra-experimental-features nix-command hash to-sri --type sha256 "$latestHash")"
+    local localHash="$(nix --extra-experimental-features nix-command eval --raw --file . androidStudioPackages."${channel}".unwrapped.src.drvAttrs.outputHash)"
+    sed -i "s~${localHash}~${latestSri}~g" "${DEFAULT_NIX}"
 
     # Match the formatting of default.nix: `version = "2021.3.1.14"; # "Android Studio Dolphin (2021.3.1) Beta 5"`
     local versionString="${latestVersion}\"; # \"$(getLatest "name" "${channel}")\""
-    sed -i "s/${localVersion}.*/${versionString}/g" "${DEFAULT_NIX}"
+    sed -i "s~${localVersion}.*~${versionString}~g" "${DEFAULT_NIX}"
     echo "updated ${channel} to ${latestVersion}"
 }