From 839fdd204860a3fb4899734c9f08504210b51515 Mon Sep 17 00:00:00 2001 From: Olivier Date: Sun, 11 Jan 2026 21:34:04 -0400 Subject: [PATCH] Remove cursor-release.nix and integrate its content into flake.nix for better management of version and architecture-specific sources. --- README.md | 4 +-- cursor-release.nix | 17 ---------- flake.nix | 35 ++++++++++--------- update-cursor.sh | 85 ++++++++++++++++++++++++++++++++-------------- 4 files changed, 81 insertions(+), 60 deletions(-) delete mode 100644 cursor-release.nix diff --git a/README.md b/README.md index 4ac0b07..0c727a3 100644 --- a/README.md +++ b/README.md @@ -75,11 +75,11 @@ To update to a specific version: ## How It Works ### Automatic Updates -The CI workflow in `.github/workflows/update-cursor.yml` runs daily and: +In CI (or manually), `./update-cursor.sh` can be run daily and: 1. Checks Cursor's API for the latest version 2. Only updates if a new version is available 3. Downloads the AppImage and calculates SHA256 hash -4. Updates `cursor-release.nix` with the new version and **per-architecture hashes** (`x86_64-linux` + `aarch64-linux`) +4. Updates the managed block in `flake.nix` with the new version and **per-architecture sources** (`x86_64-linux` + `aarch64-linux`) 5. Tests the build and commits changes 6. Pushes the update back to the repository diff --git a/cursor-release.nix b/cursor-release.nix deleted file mode 100644 index ca94be7..0000000 --- a/cursor-release.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ - # Managed by ./update-cursor.sh - # - # Notes: - # - `sha256` values are Nix base32 hashes (as used by `fetchurl { sha256 = "..."; }`). - version = "2.3.34"; - - url = { - x86_64-linux = "https://downloads.cursor.com/production/643ba67cd252e2888e296dd0cf34a0c5d7625b96/linux/x64/Cursor-2.3.34-x86_64.AppImage"; - aarch64-linux = "https://downloads.cursor.com/production/643ba67cd252e2888e296dd0cf34a0c5d7625b96/linux/arm64/Cursor-2.3.34-aarch64.AppImage"; - }; - - sha256 = { - x86_64-linux = "1sn3fzby9nn388azyp73fqsmnq51n9z42q208prn3l2zw44brjv6"; - aarch64-linux = "1msdsv0h53slmlnsckrl32g9pnqxx44039yky59h78pgfwy5kjgg"; - }; -} diff --git a/flake.nix b/flake.nix index 74cbba8..1b460b1 100644 --- a/flake.nix +++ b/flake.nix @@ -9,18 +9,30 @@ let lib = nixpkgs.lib; systems = [ "x86_64-linux" "aarch64-linux" ]; - cursorRelease = import ./cursor-release.nix; - channelForSystem = { - x86_64-linux = "linux-x64"; - aarch64-linux = "linux-arm64"; + # BEGIN managed by ./update-cursor.sh + version = "2.3.34"; + sources = { + x86_64-linux = { + url = "https://downloads.cursor.com/production/643ba67cd252e2888e296dd0cf34a0c5d7625b96/linux/x64/Cursor-2.3.34-x86_64.AppImage"; + sha256 = "1sn3fzby9nn388azyp73fqsmnq51n9z42q208prn3l2zw44brjv6"; + }; + aarch64-linux = { + url = "https://downloads.cursor.com/production/643ba67cd252e2888e296dd0cf34a0c5d7625b96/linux/arm64/Cursor-2.3.34-aarch64.AppImage"; + sha256 = "1msdsv0h53slmlnsckrl32g9pnqxx44039yky59h78pgfwy5kjgg"; + }; }; + # END managed by ./update-cursor.sh pkgsFor = system: import nixpkgs { inherit system; }; - buildCursor = pkgs: { version, url, sha256 }: + buildCursor = { pkgs, system }: let - src = pkgs.fetchurl { inherit url sha256; }; + source = sources.${system} or (throw "Unsupported system: ${system}"); + src = pkgs.fetchurl { + url = source.url; + sha256 = source.sha256; + }; # Extract the AppImage to get access to the icon and desktop file appimageContents = pkgs.appimageTools.extract { @@ -114,19 +126,10 @@ packages = lib.genAttrs systems (system: let pkgs = pkgsFor system; - version = cursorRelease.version; - channel = channelForSystem.${system} or (throw "Unsupported system: ${system}"); - # Prefer the stable resolved downloads.cursor.com URL stored by ./update-cursor.sh. - # Fallback to the API URL for older cursor-release.nix files. - url = - if cursorRelease ? url && cursorRelease.url ? ${system} - then cursorRelease.url.${system} - else "https://api2.cursor.sh/updates/download/golden/${channel}/cursor/${version}"; - sha256 = cursorRelease.sha256.${system} or "0000000000000000000000000000000000000000000000000000"; in { default = self.packages.${system}.cursor; - cursor = buildCursor pkgs { inherit version url sha256; }; + cursor = buildCursor { inherit pkgs system; }; }); # Overlay for easy integration into other flakes diff --git a/update-cursor.sh b/update-cursor.sh index 4a47bd1..9b892c5 100755 --- a/update-cursor.sh +++ b/update-cursor.sh @@ -10,7 +10,10 @@ set -euo pipefail # ./update-cursor.sh 2.2 # follow a major.minor pointer only SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -RELEASE_FILE="$SCRIPT_DIR/cursor-release.nix" +FLAKE_FILE="$SCRIPT_DIR/flake.nix" +MANAGED_BEGIN="# BEGIN managed by ./update-cursor.sh" +MANAGED_END="# END managed by ./update-cursor.sh" +INDENT=" " CHANNEL_FOR_SYSTEM_x86_64_linux="linux-x64" CHANNEL_FOR_SYSTEM_aarch64_linux="linux-arm64" @@ -108,9 +111,13 @@ is_pointer() { [[ "${1:-}" == "latest" || "${1:-}" =~ ^[0-9]+\.[0-9]+$ ]] } -# Function to get current version from cursor-release.nix +# Function to get current version from flake.nix managed block get_current_version() { - grep -o 'version = "[^"]*"' "$RELEASE_FILE" | head -1 | cut -d'"' -f2 + awk -v begin="$MANAGED_BEGIN" -v end="$MANAGED_END" ' + $0 ~ begin {inblock=1; next} + $0 ~ end {inblock=0} + inblock && match($0, /version = "([^"]+)";/, m) { print m[1]; exit } + ' "$FLAKE_FILE" } # Derive major.minor track from a full version (e.g. 2.2.43 -> 2.2). @@ -159,7 +166,7 @@ prefetch_sha256() { echo "$hash" } -# Function to update cursor-release.nix +# Update flake.nix managed block with a new version + per-system urls/hashes update_release() { local version="$1" @@ -175,30 +182,58 @@ update_release() { echo "x86_64-linux sha256: $sha_x86" echo "aarch64-linux sha256: $sha_aarch64" + if ! grep -qF "$MANAGED_BEGIN" "$FLAKE_FILE" || ! grep -qF "$MANAGED_END" "$FLAKE_FILE"; then + echo "Error: Could not find managed block markers in $FLAKE_FILE" >&2 + echo "Expected lines containing:" >&2 + echo " $MANAGED_BEGIN" >&2 + echo " $MANAGED_END" >&2 + return 1 + fi + # Create backup - cp "$RELEASE_FILE" "$RELEASE_FILE.backup" + cp "$FLAKE_FILE" "$FLAKE_FILE.backup" - cat > "$RELEASE_FILE" <> "$tmp_file" - sha256 = { - x86_64-linux = "$sha_x86"; - aarch64-linux = "$sha_aarch64"; - }; -} + cat >> "$tmp_file" <> "$tmp_file" + inblock=0 + continue + fi + + if [[ "$inblock" -eq 1 ]]; then + continue + fi + + printf '%s\n' "$line" >> "$tmp_file" + done < "$FLAKE_FILE" + + mv "$tmp_file" "$FLAKE_FILE" + echo "Updated flake.nix managed block with version $version" } # Function to test the flake @@ -289,7 +324,7 @@ main() { echo "CURSOR_VERSION_INFO=completed:$current_version:$target_version" >> "$GITHUB_OUTPUT" fi echo "You can now commit the changes:" - echo " git add flake.nix cursor-release.nix" + echo " git add flake.nix" echo " git commit -m \"Update Cursor to version $target_version\"" else echo "Update cancelled." @@ -304,8 +339,8 @@ check_dependencies() { if ! command -v curl >/dev/null 2>&1; then missing_deps+=("curl") fi - if [[ ! -f "$RELEASE_FILE" ]]; then - missing_deps+=("cursor-release.nix (missing file)") + if [[ ! -f "$FLAKE_FILE" ]]; then + missing_deps+=("flake.nix (missing file)") fi if [[ ${#missing_deps[@]} -gt 0 ]]; then