Support for aarch64

This commit is contained in:
2025-12-24 16:38:33 -04:00
parent 6af7e257f1
commit ead1ff7034
6 changed files with 143 additions and 79 deletions
+76 -47
View File
@@ -2,11 +2,14 @@
set -euo pipefail
# Script to manually update Cursor version in the flake
# Script to manually update Cursor version/hashes used by the flake
# Usage: ./update-cursor.sh [version]
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
FLAKE_FILE="$SCRIPT_DIR/flake.nix"
RELEASE_FILE="$SCRIPT_DIR/cursor-release.nix"
CHANNEL_FOR_SYSTEM_x86_64_linux="linux-x64"
CHANNEL_FOR_SYSTEM_aarch64_linux="linux-arm64"
# Function to get latest version from API redirect
get_latest_version() {
@@ -23,56 +26,86 @@ get_latest_version() {
fi
}
# Function to get current version from flake.nix
# Function to get current version from cursor-release.nix
get_current_version() {
grep -o 'version = "[^"]*"' "$FLAKE_FILE" | head -1 | cut -d'"' -f2
grep -o 'version = "[^"]*"' "$RELEASE_FILE" | head -1 | cut -d'"' -f2
}
# Function to update flake.nix
update_flake() {
local version="$1"
local appimage_url="https://api2.cursor.sh/updates/download/golden/linux-x64/cursor/$version"
echo "Fetching AppImage from: $appimage_url"
# Get the actual download URL by following redirects
local actual_url
actual_url=$(curl -s -I "$appimage_url" | grep -i location | cut -d' ' -f2 | tr -d '\r\n')
if [[ -z "$actual_url" ]]; then
echo "Error: Could not get actual download URL"
# Function to compute sha256 for a given system+version
prefetch_sha256() {
local system="$1"
local version="$2"
local channel=""
case "$system" in
x86_64-linux) channel="$CHANNEL_FOR_SYSTEM_x86_64_linux" ;;
aarch64-linux) channel="$CHANNEL_FOR_SYSTEM_aarch64_linux" ;;
*) echo "Error: Unsupported system: $system" >&2; return 1 ;;
esac
local url="https://api2.cursor.sh/updates/download/golden/${channel}/cursor/${version}"
if ! command -v nix-prefetch-url >/dev/null 2>&1; then
echo "Error: nix-prefetch-url not found. Please install Nix (or nix-prefetch-url) and retry." >&2
return 1
fi
echo "Actual download URL: $actual_url"
# Get SHA256 hash
local sha256
if command -v nix-prefetch-url >/dev/null 2>&1; then
sha256=$(nix-prefetch-url --type sha256 "$actual_url")
else
echo "Warning: nix-prefetch-url not found. You'll need to update the SHA256 manually."
sha256="0000000000000000000000000000000000000000000000000000"
# IMPORTANT: this function is captured by command substitution. Keep stdout as the hash only.
echo "Prefetching ($system) from: $url" >&2
local out hash
out="$(nix-prefetch-url --type sha256 "$url" 2>&1)"
echo "$out" >&2
# Extract the Nix base32 sha256 hash (52 chars, Nix alphabet).
hash="$(echo "$out" | grep -Eo '[0-9abcdfghijklmnpqrsvwxyz]{52}' | tail -n1 || true)"
if [[ -z "$hash" ]]; then
echo "Error: Could not parse sha256 from nix-prefetch-url output for $system" >&2
return 1
fi
echo "SHA256: $sha256"
echo "$hash"
}
# Function to update cursor-release.nix
update_release() {
local version="$1"
echo "Computing hashes for version: $version"
local sha_x86 sha_aarch64
sha_x86="$(prefetch_sha256 x86_64-linux "$version")"
sha_aarch64="$(prefetch_sha256 aarch64-linux "$version")"
echo "x86_64-linux sha256: $sha_x86"
echo "aarch64-linux sha256: $sha_aarch64"
# Create backup
cp "$FLAKE_FILE" "$FLAKE_FILE.backup"
# Update flake.nix - be more specific to avoid replacing nixpkgs URL
sed -i "s/version = \"[^\"]*\"/version = \"$version\"/" "$FLAKE_FILE"
sed -i "/cursor = buildCursor {/,/};/s|url = \"[^\"]*\"|url = \"$actual_url\"|" "$FLAKE_FILE"
sed -i "/cursor = buildCursor {/,/};/s/sha256 = \"[^\"]*\"/sha256 = \"$sha256\"/" "$FLAKE_FILE"
echo "Updated flake.nix with version $version"
cp "$RELEASE_FILE" "$RELEASE_FILE.backup"
cat > "$RELEASE_FILE" <<EOF
{
# Managed by ./update-cursor.sh
#
# Notes:
# - \`sha256\` values are Nix base32 hashes (as used by \`fetchurl { sha256 = "..."; }\`).
version = "$version";
sha256 = {
x86_64-linux = "$sha_x86";
aarch64-linux = "$sha_aarch64";
};
}
EOF
echo "Updated cursor-release.nix with version $version"
}
# Function to test the flake
test_flake() {
echo "Testing flake..."
if command -v nix >/dev/null 2>&1; then
nix flake check
nix flake check --no-build
echo "Flake check passed!"
else
echo "Warning: nix command not found. Skipping flake check."
@@ -110,9 +143,6 @@ main() {
fi
echo "Update needed: $current_version -> $target_version"
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
echo "CURSOR_VERSION_INFO=updated:$current_version:$target_version" >> "$GITHUB_OUTPUT"
fi
# Check if running in CI/GitHub Actions (auto-confirm)
if [[ -n "${CI:-}" ]] || [[ -n "${GITHUB_ACTIONS:-}" ]]; then
@@ -124,14 +154,14 @@ main() {
fi
if [[ $REPLY =~ ^[Yy]$ ]]; then
update_flake "$target_version"
update_release "$target_version"
test_flake
echo "Update completed successfully!"
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
echo "CURSOR_VERSION_INFO=completed:$current_version:$target_version" >> "$GITHUB_OUTPUT"
fi
echo "You can now commit the changes:"
echo " git add flake.nix"
echo " git add flake.nix cursor-release.nix"
echo " git commit -m \"Update Cursor to version $target_version\""
else
echo "Update cancelled."
@@ -146,9 +176,8 @@ check_dependencies() {
if ! command -v curl >/dev/null 2>&1; then
missing_deps+=("curl")
fi
if ! command -v jq >/dev/null 2>&1; then
missing_deps+=("jq")
if [[ ! -f "$RELEASE_FILE" ]]; then
missing_deps+=("cursor-release.nix (missing file)")
fi
if [[ ${#missing_deps[@]} -gt 0 ]]; then