From df6d5105d03ccb8f3cb9295b0a7b8275566e270b Mon Sep 17 00:00:00 2001 From: aspauldingcode Date: Wed, 15 Jan 2025 18:20:11 -0700 Subject: [PATCH] cursor -> add darwin, modify update script, add maintainer --- pkgs/by-name/co/code-cursor/package.nix | 61 +++++++++++++++++++++---- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/pkgs/by-name/co/code-cursor/package.nix b/pkgs/by-name/co/code-cursor/package.nix index bf46c9444b726b..163ba99fbe0450 100644 --- a/pkgs/by-name/co/code-cursor/package.nix +++ b/pkgs/by-name/co/code-cursor/package.nix @@ -5,7 +5,9 @@ appimageTools, makeWrapper, writeScript, + undmg, }: + let pname = "cursor"; version = "0.44.11"; @@ -19,11 +21,21 @@ let url = "https://download.todesktop.com/230313mzl4w4u92/cursor-0.44.11-build-250103fqxdt5u9z-arm64.AppImage"; hash = "sha256-mxq7tQJfDccE0QsZDZbaFUKO0Xc141N00ntX3oEYRcc="; }; + x86_64-darwin = fetchurl { + url = "https://download.todesktop.com/230313mzl4w4u92/Cursor%200.44.11%20-%20Build%20250103fqxdt5u9z-x64.dmg"; + hash = "sha256-JKPClcUD2W3KWRlRTomDF4FOOA1DDw3iAQ+IH7yan+E="; + }; + aarch64-darwin = fetchurl { + url = "https://download.todesktop.com/230313mzl4w4u92/Cursor%200.44.11%20-%20Build%20250103fqxdt5u9z-arm64.dmg"; + hash = "sha256-0HDnRYfy+jKJy5dvaulQczAoFqYmGGWcdhIkaFZqEPA="; + }; }; supportedPlatforms = [ "x86_64-linux" "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" ]; src = sources.${stdenvNoCC.hostPlatform.system}; @@ -54,15 +66,32 @@ let runHook postInstall ''; + darwinInstallPhase = '' + runHook preInstall + + mkdir -p $out/Applications + cp -r *.app $out/Applications/ + + runHook postInstall + ''; + + darwinUnpackPhase = '' + runHook preUnpack + + undmg $src + + runHook postUnpack + ''; in stdenvNoCC.mkDerivation { inherit pname version; - src = wrappedAppImage; + inherit src; - nativeBuildInputs = [ makeWrapper ]; + nativeBuildInputs = [ makeWrapper ] ++ lib.optionals stdenvNoCC.isDarwin [ undmg ]; - installPhase = appimageInstall; + unpackPhase = if stdenvNoCC.isDarwin then darwinUnpackPhase else null; + installPhase = if stdenvNoCC.isDarwin then darwinInstallPhase else appimageInstall; passthru = { inherit sources; @@ -72,9 +101,21 @@ stdenvNoCC.mkDerivation { set -eu -o pipefail baseUrl="https://download.todesktop.com/230313mzl4w4u92" latestLinux="$(curl -s $baseUrl/latest-linux.yml)" - version="$(echo "$latestLinux" | yq -r .version)" - filename="$(echo "$latestLinux" | yq -r '.files[] | .url | select(. | endswith(".AppImage"))')" - linuxStem="$(echo "$filename" | sed -E s/^\(cursor-.+-build-.*\)-.+$/\\1/)" + latestDarwin="$(curl -s $baseUrl/latest-mac.yml)" + linuxVersion="$(echo "$latestLinux" | yq -r .version)" + 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"))')" + linuxStem="$(echo "$linuxFilename" | sed -E s/^\(cursor-.+-build-.*\)-.+$/\\1/)" + + darwinFilename="$(echo "$latestDarwin" | yq -r '.files[] | .url | select(. | endswith(".dmg"))')" + darwinStem="$(echo "$darwinFilename" | sed -E s/^\(Cursor.+-Build.*\)-.+$/\\1/)" currentVersion=$(nix-instantiate --eval -E "with import ./. {}; code-cursor.version or (lib.getVersion code-cursor)" | tr -d '"') @@ -84,6 +125,10 @@ stdenvNoCC.mkDerivation { 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 @@ -103,7 +148,7 @@ stdenvNoCC.mkDerivation { license = lib.licenses.unfree; sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; maintainers = with lib.maintainers; [ sarahec ]; - platforms = lib.platforms.linux; + platforms = lib.platforms.linux ++ lib.platforms.darwin; mainProgram = "cursor"; }; -} +} \ No newline at end of file