···1+#!/usr/bin/env nix-shell
2+#!nix-shell -i bash -p curl gnugrep gnused jq
3+# shellcheck shell=bash
4+5+set -euo pipefail
6+7+# Script configuration
8+SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
9+PACKAGE_NIX="${SCRIPT_DIR}/package.nix"
10+SOURCES_JSON="${SCRIPT_DIR}/sources.json"
11+12+# Platform configuration
13+declare -A PLATFORM_URLS=(
14+ ["x86_64-linux"]="https://prod.download.desktop.kiro.dev/stable/metadata-linux-x64-stable.json"
15+ ["x86_64-darwin"]="https://prod.download.desktop.kiro.dev/stable/metadata-dmg-darwin-x64-stable.json"
16+ ["aarch64-darwin"]="https://prod.download.desktop.kiro.dev/stable/metadata-dmg-darwin-arm64-stable.json"
17+)
18+19+# Data storage
20+declare -A platform_versions
21+declare -A platform_urls
22+declare -A platform_hashes
23+24+# Error handling
25+error_exit() {
26+ echo "Error: $1" >&2
27+ exit 1
28+}
29+30+# Script execution starts here
31+echo "Starting Kiro update process..."
32+33+# Fetch metadata for all platforms
34+echo "Fetching platform information..."
35+for platform in "${!PLATFORM_URLS[@]}"; do
36+ url="${PLATFORM_URLS[$platform]}"
37+ echo "Fetching metadata for $platform..."
38+39+ if ! response=$(curl -fsSL "$url"); then
40+ error_exit "Failed to fetch metadata for $platform from $url"
41+ fi
42+43+ # Extract file URL and version from metadata
44+ file_url=$(echo "$response" | jq -r '
45+ .releases[0].updateTo
46+ | select(.url | test("\\.(tar|dmg)(\\.|$)"))
47+ | .url' | head -1)
48+49+ if [[ -z "$file_url" || "$file_url" == "null" ]]; then
50+ error_exit "Could not find a valid file URL for $platform in metadata"
51+ fi
52+53+ version=$(echo "$response" | jq -r '.currentRelease')
54+ if [[ -z "$version" || "$version" == "null" ]]; then
55+ error_exit "Could not extract version for $platform from metadata"
56+ fi
57+58+ platform_versions["$platform"]="$version"
59+ platform_urls["$platform"]="$file_url"
60+done
61+62+# Determine the maximum version
63+max_version=""
64+for platform in "${!platform_versions[@]}"; do
65+ version="${platform_versions[$platform]}"
66+ if [[ -z "$max_version" ]] || [[ "$version" > "$max_version" ]]; then
67+ max_version="$version"
68+ fi
69+done
70+echo "Latest version across all platforms: $max_version"
71+72+# Check if update is needed
73+if [[ ! -f "$PACKAGE_NIX" ]]; then
74+ error_exit "package.nix not found at $PACKAGE_NIX"
75+fi
76+current_version=$(grep -E '^ version = ' "$PACKAGE_NIX" | cut -d'"' -f2)
77+if [[ -z "$current_version" ]]; then
78+ error_exit "Could not extract current version from package.nix"
79+fi
80+if [[ "$max_version" == "$current_version" ]]; then
81+ echo "No update needed. Current version is already the latest: $current_version"
82+ exit 0
83+fi
84+85+echo "Updating to version: $max_version"
86+echo "Calculating hashes..."
87+for platform in "${!platform_urls[@]}"; do
88+ echo " Calculating hash for $platform..."
89+ platform_hashes["$platform"]=$(nix hash convert --hash-algo sha256 "$(nix-prefetch-url "${platform_urls[$platform]}")")
90+done
91+92+# Update package.nix and generate sources.json
93+echo "Updating package.nix..."
94+sed -i "s/version = \".*\"/version = \"$max_version\"/" "$PACKAGE_NIX"
95+96+echo "Generating sources.json..."
97+json_content="{}"
98+for platform in "${!platform_urls[@]}"; do
99+ json_content=$(echo "$json_content" | jq --arg platform "$platform" \
100+ --arg url "${platform_urls[$platform]}" \
101+ --arg hash "${platform_hashes[$platform]}" \
102+ '. + {($platform): {url: $url, hash: $hash}}')
103+done
104+echo "$json_content" >"$SOURCES_JSON"
105+106+echo "Successfully updated package.nix to version $max_version"
107+echo "Hashes calculated and updated:"
108+for platform in "${!platform_hashes[@]}"; do
109+ echo " $platform: ${platform_hashes[$platform]}"
110+done
+6
pkgs/top-level/all-packages.nix
···13807 nodejs = nodejs_20;
13808 };
1380900000013810 whispers = with python3Packages; toPythonApplication whispers;
1381113812 # Should always be the version with the most features
···13807 nodejs = nodejs_20;
13808 };
1380913810+ kiro = callPackage ../by-name/ki/kiro/package.nix {
13811+ vscode-generic = ../applications/editors/vscode/generic.nix;
13812+ };
13813+ kiro-fhs = kiro.fhs;
13814+ kiro-fhsWithPackages = kiro.fhsWithPackages;
13815+13816 whispers = with python3Packages; toPythonApplication whispers;
1381713818 # Should always be the version with the most features