diff --git a/pkgs/by-name/co/code-cursor/package.nix b/pkgs/by-name/co/code-cursor/package.nix index 07b98b9e796c..bb57c3b5d15f 100644 --- a/pkgs/by-name/co/code-cursor/package.nix +++ b/pkgs/by-name/co/code-cursor/package.nix @@ -2,33 +2,73 @@ lib, stdenvNoCC, fetchurl, + + # build appimageTools, + + # linux dependencies + alsa-lib, + at-spi2-atk, + autoPatchelfHook, + cairo, + cups, + curlWithGnuTls, + egl-wayland, + expat, + fontconfig, + freetype, + ffmpeg, + glib, + glibc, + glibcLocales, + gtk3, + libappindicator-gtk3, + libdrm, + libgbm, + libGL, + libnotify, + libva-minimal, + libxkbcommon, + libxkbfile, makeWrapper, - writeScript, + nspr, + nss, + pango, + pciutils, + pulseaudio, + vivaldi-ffmpeg-codecs, + vulkan-loader, + wayland, + + # linux installation + rsync, + + # darwin build undmg, }: let pname = "cursor"; - version = "0.45.14"; + version = "0.47.8"; inherit (stdenvNoCC) hostPlatform; sources = { x86_64-linux = fetchurl { - url = "https://download.todesktop.com/230313mzl4w4u92/cursor-0.45.14-build-250219jnihavxsz-x86_64.AppImage"; - hash = "sha256-5MGWJi8TP+13jZf6YMMUU5uYY/3OBTFxtGpirvgj8ZI="; - }; - aarch64-linux = fetchurl { - url = "https://download.todesktop.com/230313mzl4w4u92/cursor-0.45.14-build-250219jnihavxsz-arm64.AppImage"; - hash = "sha256-8OUlPuPNgqbGe2x7gG+m3n3u6UDvgnVekkjJ08pVORs="; + url = "https://downloads.cursor.com/production/82ef0f61c01d079d1b7e5ab04d88499d5af500e3/linux/x64/Cursor-0.47.8-82ef0f61c01d079d1b7e5ab04d88499d5af500e3.deb.glibc2.25-x86_64.AppImage"; + hash = "sha256-3Ph5A+x1hW0SOaX8CF7b/8Fq7eMeBkG1ju9vud6Cbn0="; }; + # Cursor's release for aarch64-linux is the wrong version (temporarily). + # aarch64-linux = fetchurl { + # url = "https://download.todesktop.com/230313mzl4w4u92/cursor-0.45.14-build-250219jnihavxsz-arm64.AppImage"; + # hash = "sha256-8OUlPuPNgqbGe2x7gG+m3n3u6UDvgnVekkjJ08pVORs="; + # }; x86_64-darwin = fetchurl { - url = "https://download.todesktop.com/230313mzl4w4u92/Cursor%200.45.14%20-%20Build%20250219jnihavxsz-x64.dmg"; - hash = "sha256-NyDY74PZjSjpuTSVaO/l9adPcLX1kytyrFGQjJ/8WcQ="; + url = "https://downloads.cursor.com/production/82ef0f61c01d079d1b7e5ab04d88499d5af500e3/darwin/x64/Cursor-darwin-x64.dmg"; + hash = "sha256-T5N8b/6HexQ2ZchWUb9CL3t9ks93O9WJgrDtxfE1SgU="; }; aarch64-darwin = fetchurl { - url = "https://download.todesktop.com/230313mzl4w4u92/Cursor%200.45.14%20-%20Build%20250219jnihavxsz-arm64.dmg"; - hash = "sha256-A503TxDDFENqMnc1hy/lMMyIgC7YwwRYPJy+tp649Eg="; + url = "https://downloads.cursor.com/production/82ef0f61c01d079d1b7e5ab04d88499d5af500e3/darwin/arm64/Cursor-darwin-arm64.dmg"; + hash = "sha256-ycroylfEZY/KfRiXvfOuTdyyglbg/J7DU12u6Xrsk0s="; }; }; @@ -52,9 +92,55 @@ stdenvNoCC.mkDerivation { src = if hostPlatform.isLinux then wrappedAppimage else source; nativeBuildInputs = - lib.optionals hostPlatform.isLinux [ makeWrapper ] + lib.optionals hostPlatform.isLinux [ + autoPatchelfHook + glibcLocales + makeWrapper + rsync + ] ++ lib.optionals hostPlatform.isDarwin [ undmg ]; + buildInputs = lib.optionals hostPlatform.isLinux [ + alsa-lib + at-spi2-atk + cairo + cups + curlWithGnuTls + egl-wayland + expat + ffmpeg + glib + gtk3 + libdrm + libgbm + libGL + libGL + libva-minimal + libxkbcommon + libxkbfile + nspr + nss + pango + pulseaudio + vivaldi-ffmpeg-codecs + vulkan-loader + wayland + ]; + + runtimeDependencies = lib.optionals hostPlatform.isLinux [ + egl-wayland + ffmpeg + glibc + libappindicator-gtk3 + libnotify + libxkbfile + pciutils + pulseaudio + wayland + fontconfig + freetype + ]; + sourceRoot = lib.optionalString hostPlatform.isDarwin "."; # Don't break code signing @@ -68,13 +154,13 @@ stdenvNoCC.mkDerivation { ${lib.optionalString hostPlatform.isLinux '' cp -r bin $out/bin - mkdir -p $out/share/cursor - cp -a ${appimageContents}/locales $out/share/cursor - cp -a ${appimageContents}/resources $out/share/cursor - cp -a ${appimageContents}/usr/share/icons $out/share/ - install -Dm 644 ${appimageContents}/cursor.desktop -t $out/share/applications/ + # mkdir -p $out/share/cursor + # cp -ar ${appimageContents}/usr/share $out/ - substituteInPlace $out/share/applications/cursor.desktop --replace-fail "AppRun" "cursor" + rsync -a -q ${appimageContents}/usr/share $out/ --exclude "*.so" + + # Fix the desktop file to point to the correct location + substituteInPlace $out/share/applications/cursor.desktop --replace-fail "/usr/share/cursor/cursor" "$out/share/cursor/cursor" wrapProgram $out/bin/cursor \ --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}} --no-update" @@ -98,52 +184,7 @@ stdenvNoCC.mkDerivation { passthru = { inherit sources; - updateScript = writeScript "update.sh" '' - #!/usr/bin/env nix-shell - #!nix-shell -i bash -p curl yq coreutils gnused trurl common-updater-scripts - set -eu -o pipefail - - baseUrl="https://download.todesktop.com/230313mzl4w4u92" - latestLinux="$(curl -s $baseUrl/latest-linux.yml)" - latestDarwin="$(curl -s $baseUrl/latest-mac.yml)" - linuxVersion="$(echo "$latestLinux" | yq -r .version)" - - currentVersion=$(nix-instantiate --eval -E "with import ./. {}; code-cursor.version or (lib.getVersion code-cursor)" | tr -d '"') - - if [[ "$linuxVersion" != "$currentVersion" ]]; then - darwinVersion="$(echo "$latestDarwin" | yq -r .version)" - if [ "$linuxVersion" != "$darwinVersion" ]; then - echo "Linux version ($linuxVersion) and Darwin version ($darwinVersion) do not match" - exit 1 - fi - version="$linuxVersion" - - linuxFilename="$(echo "$latestLinux" | yq -r '.files[] | .url | select(. | endswith(".AppImage"))' | head -n 1)" - linuxStem="$(echo "$linuxFilename" | sed -E s/^\(.+build.+\)-[^-]+AppImage$/\\1/)" - - darwinFilename="$(echo "$latestDarwin" | yq -r '.files[] | .url | select(. | endswith(".dmg"))' | head -n 1)" - darwinStem="$(echo "$darwinFilename" | sed -E s/^\(.+Build[^-]+\)-.+dmg$/\\1/)" - - for platform in "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"; do - if [ $platform = "x86_64-linux" ]; then - url="$baseUrl/$linuxStem-x86_64.AppImage" - elif [ $platform = "aarch64-linux" ]; then - url="$baseUrl/$linuxStem-arm64.AppImage" - elif [ $platform = "x86_64-darwin" ]; then - url="$baseUrl/$darwinStem-x64.dmg" - elif [ $platform = "aarch64-darwin" ]; then - url="$baseUrl/$darwinStem-arm64.dmg" - else - echo "Unsupported platform: $platform" - exit 1 - fi - - url=$(trurl --accept-space "$url") - hash=$(nix-hash --to-sri --type sha256 "$(nix-prefetch-url "$url" --name "cursor-$version")") - update-source-version code-cursor $version $hash $url --system=$platform --ignore-same-version --source-key="sources.$platform" - done - fi - ''; + updateScript = ./update.sh; }; meta = { @@ -156,7 +197,13 @@ stdenvNoCC.mkDerivation { sarahec aspauldingcode ]; - platforms = lib.platforms.linux ++ lib.platforms.darwin; + platforms = [ + "x86_64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + # Temporary: Cursor doesn't supply a 0.47.8 build for aarch64-linux + badPlatforms = [ "aarch64-linux" ]; mainProgram = "cursor"; }; } diff --git a/pkgs/by-name/co/code-cursor/update.sh b/pkgs/by-name/co/code-cursor/update.sh new file mode 100755 index 000000000000..e0ee1c274321 --- /dev/null +++ b/pkgs/by-name/co/code-cursor/update.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p curl yq coreutils common-updater-scripts +set -eu -o pipefail + +currentVersion=$(nix-instantiate --eval -E "with import ./. {}; code-cursor.version or (lib.getVersion code-cursor)" | tr -d '"') + +declare -A platforms=( [x86_64-linux]='linux-x64' [aarch64-linux]='linux-arm64' [x86_64-darwin]='darwin-x64' [aarch64-darwin]='darwin-arm64' ) +declare -A updates=( ) +first_version="" + +for platform in ${!platforms[@]}; do + api_platform=${platforms[$platform]} + result=$(curl -s "https://api2.cursor.sh/updates/api/download/stable/$api_platform/cursor") + version=$(echo $result | jq -r '.version') + if [[ "$version" == "$currentVersion" ]]; then + exit 0 + fi + if [[ -z "$first_version" ]]; then + first_version=$version + first_platform=$platform + elif [[ "$version" != "$first_version" ]]; then + >&2 echo "Multiple versions found: $first_version ($first_platform) and $version ($platform)" + exit 1 + fi + url=$(echo $result | jq -r '.downloadUrl') + # Exits with code 22 if not downloadable + curl --output /dev/null --silent --head --fail "$url" + updates+=( [$platform]="$result" ) +done + +# Install updates +for platform in ${!updates[@]}; do + result=${updates[$platform]} + version=$(echo $result | jq -r '.version') + url=$(echo $result | jq -r '.downloadUrl') + source=$(nix-prefetch-url "$url" --name "cursor-$version") + hash=$(nix-hash --to-sri --type sha256 "$source") + update-source-version code-cursor $version $hash "$url" --system=$platform --ignore-same-version --source-key="sources.$platform" +done