From 59dabeb63027072a4fe3badaace58089a3c83c9b Mon Sep 17 00:00:00 2001 From: aspauldingcode Date: Mon, 13 Jan 2025 07:58:07 -0800 Subject: [PATCH] cursor -> add platforms --- pkgs/by-name/co/code-cursor/package.nix | 109 +++++++++++++++++------- 1 file changed, 79 insertions(+), 30 deletions(-) diff --git a/pkgs/by-name/co/code-cursor/package.nix b/pkgs/by-name/co/code-cursor/package.nix index ad1bb1e7ff339..28cff3b1f8a24 100644 --- a/pkgs/by-name/co/code-cursor/package.nix +++ b/pkgs/by-name/co/code-cursor/package.nix @@ -5,57 +5,103 @@ appimageTools, makeWrapper, writeScript, + undmg, }: + let pname = "cursor"; version = "0.44.11"; appKey = "230313mzl4w4u92"; + + # tip: download and use nix hash file to get the hash, since mac dmg urls contain spaces / %20s + sources = { + x86_64-linux = { + url = "https://download.todesktop.com/230313mzl4w4u92/cursor-0.44.11-build-250103fqxdt5u9z-x86_64.AppImage"; + hash = "sha256-eOZuofnpED9F6wic0S9m933Tb7Gq7cb/v0kRDltvFVg="; + }; + aarch64-linux = { + url = "https://download.todesktop.com/230313mzl4w4u92/cursor-0.44.11-build-250103fqxdt5u9z-arm64.AppImage"; + hash = "sha256-mxq7tQJfDccE0QsZDZbaFUKO0Xc141N00ntX3oEYRcc="; + }; + x86_64-darwin = { + url = "https://download.todesktop.com/230313mzl4w4u92/Cursor%200.44.11%20-%20Build%20250103fqxdt5u9z-x64.dmg"; + hash = "sha256-JKPClcUD2W3KWRlRTomDF4FOOA1DDw3iAQ+IH7yan+E="; + }; + aarch64-darwin = { + url = "https://download.todesktop.com/230313mzl4w4u92/Cursor%200.44.11%20-%20Build%20250103fqxdt5u9z-arm64.dmg"; + hash = "sha256-0HDnRYfy+jKJy5dvaulQczAoFqYmGGWcdhIkaFZqEPA="; + }; + }; + src = fetchurl { - url = "https://download.todesktop.com/230313mzl4w4u92/cursor-0.44.11-build-250103fqxdt5u9z-x86_64.AppImage"; - hash = "sha256-eOZuofnpED9F6wic0S9m933Tb7Gq7cb/v0kRDltvFVg="; + inherit (sources.${stdenvNoCC.hostPlatform.system}) url hash; }; - appimageContents = appimageTools.extractType2 { inherit version pname src; }; -in -stdenvNoCC.mkDerivation { - inherit pname version; - src = appimageTools.wrapType2 { inherit version pname src; }; + installPhase = + if stdenvNoCC.isDarwin then + '' + runHook preInstall + mkdir -p $out/Applications + cp -r *.app $out/Applications/ + runHook postInstall + '' + else + '' + runHook preInstall + + mkdir -p $out/ + 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/ - nativeBuildInputs = [ makeWrapper ]; + substituteInPlace $out/share/applications/cursor.desktop --replace-fail "AppRun" "cursor" - installPhase = '' - runHook preInstall + wrapProgram $out/bin/cursor \ + --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}} --no-update" - mkdir -p $out/ - cp -r bin $out/bin + runHook postInstall + ''; - 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/ + appimageContents = appimageTools.extractType2 { inherit version pname src; }; +in +stdenvNoCC.mkDerivation { + inherit pname version src; - substituteInPlace $out/share/applications/cursor.desktop --replace-fail "AppRun" "cursor" + nativeBuildInputs = [ makeWrapper ] ++ lib.optional stdenvNoCC.isDarwin [ undmg ]; - wrapProgram $out/bin/cursor \ - --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}} --no-update" + sourceRoot = "."; - runHook postInstall - ''; + inherit installPhase; passthru.updateScript = writeScript "update.sh" '' #!/usr/bin/env nix-shell #!nix-shell -i bash -p curl yq coreutils gnused common-updater-scripts set -eu -o pipefail + + # Check both Linux and Mac versions to ensure they match latestLinux="$(curl -s https://download.todesktop.com/${appKey}/latest-linux.yml)" - version="$(echo "$latestLinux" | yq -r .version)" - filename="$(echo "$latestLinux" | yq -r '.files[] | .url | select(. | endswith(".AppImage"))')" - url="https://download.todesktop.com/${appKey}/$filename" + latestMac="$(curl -s https://download.todesktop.com/${appKey}/latest-mac.yml)" + + linuxVersion="$(echo "$latestLinux" | yq -r .version)" + macVersion="$(echo "$latestMac" | yq -r .version)" + + if [ "$linuxVersion" != "$macVersion" ]; then + echo "Warning: Linux version ($linuxVersion) and Mac version ($macVersion) differ" + exit 1 + fi + + version="$linuxVersion" currentVersion=$(nix-instantiate --eval -E "with import ./. {}; code-cursor.version or (lib.getVersion code-cursor)" | tr -d '"') if [[ "$version" != "$currentVersion" ]]; then - hash=$(nix-hash --to-sri --type sha256 "$(nix-prefetch-url "$url")") - update-source-version code-cursor "$version" "$hash" "$url" --source-key=src.src + echo "Updating code-cursor from $currentVersion to $version" + update-source-version code-cursor "$version" + else + echo "code-cursor is already up to date at version $version" fi ''; @@ -65,8 +111,11 @@ stdenvNoCC.mkDerivation { changelog = "https://cursor.com/changelog"; license = lib.licenses.unfree; sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; - maintainers = with lib.maintainers; [ sarahec ]; - platforms = [ "x86_64-linux" ]; + maintainers = with lib.maintainers; [ + sarahec + aspauldingcode + ]; + platforms = lib.platforms.linux ++ lib.platforms.darwin; mainProgram = "cursor"; }; -} +} \ No newline at end of file