Skip to content

Commit

Permalink
cursor -> add darwin, modify update script, add maintainer
Browse files Browse the repository at this point in the history
  • Loading branch information
aspauldingcode committed Jan 16, 2025
1 parent 3bb59d1 commit df6d510
Showing 1 changed file with 53 additions and 8 deletions.
61 changes: 53 additions & 8 deletions pkgs/by-name/co/code-cursor/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
appimageTools,
makeWrapper,
writeScript,
undmg,
}:

let
pname = "cursor";
version = "0.44.11";
Expand All @@ -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};
Expand Down Expand Up @@ -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;
Expand All @@ -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 '"')
Expand All @@ -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
Expand All @@ -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";
};
}
}

0 comments on commit df6d510

Please sign in to comment.