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

update cursor to 0.44.11, add multi-platform support, modify update sh #371260

Closed
Closed
Changes from 2 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
112 changes: 79 additions & 33 deletions pkgs/by-name/co/code-cursor/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,114 @@
appimageTools,
makeWrapper,
writeScript,
undmg,
}:

let
pname = "cursor";
version = "0.44.9";
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.9-build-2412268nc6pfzgo-x86_64.AppImage";
hash = "sha256-DV4Om5eAt7hDDPsyCwhALGhH36YAfvDk5u8Mnlhalsw=";
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
'';

meta = {
meta = with lib; {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with lib is deprecated, please remove and refer to lib inline (as per the original file).

Background: https://discourse.nixos.org/t/why-are-there-so-many-ways-to-reference-lib-and-do-they-matter/2920

description = "AI-powered code editor built on vscode";
homepage = "https://cursor.com";
changelog = "https://cursor.com/changelog";
license = lib.licenses.unfree;
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
maintainers = with lib.maintainers; [ sarahec ];
platforms = [ "x86_64-linux" ];
license = licenses.unfree;
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
maintainers = with maintainers; [ sarahec ];
platforms = platforms.linux ++ platforms.darwin;
mainProgram = "cursor";
};
}