Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cursor -> add platforms #373494

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 79 additions & 30 deletions pkgs/by-name/co/code-cursor/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,103 @@
appimageTools,
makeWrapper,
writeScript,
undmg,
}:

let
pname = "cursor";
version = "0.44.11";
appKey = "230313mzl4w4u92";

# tip: download and use nix hash file <filename> 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
'';

Expand All @@ -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";
};
}
}
Loading