From 794bcfa10244754e3fa3a0e33cd1a9f19663e8d0 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 formatted nixfmt cursor -> add darwin, modify update script, add maintainer formatted nixfmt Update pkgs/by-name/co/code-cursor/package.nix Co-authored-by: Sarah Clark Update pkgs/by-name/co/code-cursor/package.nix Co-authored-by: Sarah Clark Update pkgs/by-name/co/code-cursor/package.nix Co-authored-by: Sarah Clark Update pkgs/by-name/co/code-cursor/package.nix I missed that, thanks Co-authored-by: Sarah Clark add myself as a maintainer modify update script. fix src = source; cursor -> add darwin, modify update script, add maintainer formatted nixfmt cursor -> add darwin, modify update script, add maintainer formatted nixfmt Update pkgs/by-name/co/code-cursor/package.nix Co-authored-by: Sarah Clark Update pkgs/by-name/co/code-cursor/package.nix Co-authored-by: Sarah Clark Update pkgs/by-name/co/code-cursor/package.nix Co-authored-by: Sarah Clark Update pkgs/by-name/co/code-cursor/package.nix I missed that, thanks Co-authored-by: Sarah Clark add myself as a maintainer modify update script. fix src = source; tidying up the code Co-authored-by: Sarah Clark set back to src instead of source Co-authored-by: Sarah Clark tell it we don't need a build phase Co-authored-by: Sarah Clark use singular form lib.optional and fix spelling Co-authored-by: Sarah Clark inherit src Co-authored-by: Sarah Clark Update pkgs/by-name/co/code-cursor/package.nix Co-authored-by: Sarah Clark Update pkgs/by-name/co/code-cursor/package.nix Co-authored-by: Sarah Clark Update pkgs/by-name/co/code-cursor/package.nix Co-authored-by: Sarah Clark Update package.nix Co-authored-by: Sarah Clark again, format --- pkgs/by-name/co/code-cursor/package.nix | 79 +++++++++++++++++++++---- 1 file changed, 67 insertions(+), 12 deletions(-) diff --git a/pkgs/by-name/co/code-cursor/package.nix b/pkgs/by-name/co/code-cursor/package.nix index bf46c9444b726..f6576c6f349f9 100644 --- a/pkgs/by-name/co/code-cursor/package.nix +++ b/pkgs/by-name/co/code-cursor/package.nix @@ -5,11 +5,15 @@ appimageTools, makeWrapper, writeScript, + undmg, }: + let pname = "cursor"; version = "0.44.11"; + inherit (stdenvNoCC) buildPlatform; + sources = { x86_64-linux = fetchurl { url = "https://download.todesktop.com/230313mzl4w4u92/cursor-0.44.11-build-250103fqxdt5u9z-x86_64.AppImage"; @@ -19,20 +23,32 @@ 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}; + src = sources.${buildPlatform.system}; appimageContents = appimageTools.extractType2 { inherit version pname src; }; - wrappedAppImage = appimageTools.wrapType2 { inherit version pname src; }; + wrappedAppImage = appimageTools.wrapType2 { + inherit version pname src; + }; appimageInstall = '' runHook preInstall @@ -54,41 +70,77 @@ let runHook postInstall ''; + darwinInstallPhase = '' + runHook preInstall + + mkdir -p $out/Applications + cp -r *.app $out/Applications/ + + mkdir -p "$out/bin" + cat << EOF > "$out/bin/cursor" + open -na '$APP_DIR' --args "\$@" + EOF + chmod +x "$out/bin/cursor" + runHook postInstall + ''; + in stdenvNoCC.mkDerivation { inherit pname version; - src = wrappedAppImage; + src = if buildPlatform.isLinux then wrappedAppImage else null; + + dontBuild = buildPlatform.isDarwin; + + nativeBuildInputs = [ makeWrapper ] ++ lib.optional buildPlatform.isDarwin undmg; - nativeBuildInputs = [ makeWrapper ]; + sourceRoot = "."; - installPhase = appimageInstall; + installPhase = if buildPlatform.isDarwin then darwinInstallPhase else appimageInstall; passthru = { inherit sources; updateScript = writeScript "update.sh" '' #!/usr/bin/env nix-shell - #!nix-shell -i bash -p curl yq coreutils gnused common-updater-scripts + #!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)" - 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)" currentVersion=$(nix-instantiate --eval -E "with import ./. {}; code-cursor.version or (lib.getVersion code-cursor)" | tr -d '"') - if [[ "$version" != "$currentVersion" ]]; then + 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 ${lib.escapeShellArgs supportedPlatforms}; 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")") update-source-version code-cursor $version $hash $url --system=$platform --ignore-same-version --source-key="sources.$platform" done @@ -102,8 +154,11 @@ stdenvNoCC.mkDerivation { changelog = "https://cursor.com/changelog"; license = lib.licenses.unfree; sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; - maintainers = with lib.maintainers; [ sarahec ]; - platforms = lib.platforms.linux; + maintainers = with lib.maintainers; [ + sarahec + aspauldingcode + ]; + platforms = supportedPlatforms; mainProgram = "cursor"; }; }