From 9749e6bf7664cfbdefc877578ef0c0e455c0da86 Mon Sep 17 00:00:00 2001 From: Kamil Monicz Date: Fri, 6 Jun 2025 06:56:19 +0200 Subject: [PATCH 1/2] code-cursor: use generic vscode package builder --- pkgs/applications/editors/vscode/generic.nix | 5 + pkgs/by-name/co/code-cursor/package.nix | 203 +++++-------------- pkgs/top-level/all-packages.nix | 6 + 3 files changed, 67 insertions(+), 147 deletions(-) diff --git a/pkgs/applications/editors/vscode/generic.nix b/pkgs/applications/editors/vscode/generic.nix index 0f1ad0aca010d..be51acc0b3ac5 100644 --- a/pkgs/applications/editors/vscode/generic.nix +++ b/pkgs/applications/editors/vscode/generic.nix @@ -53,6 +53,7 @@ useVSCodeRipgrep ? false, ripgrep, hasVsceSign ? false, + patchVSCodePath ? true, }: stdenv.mkDerivation ( @@ -262,9 +263,13 @@ stdenv.mkDerivation ( mkdir -p "$out/share/pixmaps" cp "$out/lib/${libraryName}/resources/app/resources/linux/code.png" "$out/share/pixmaps/${iconName}.png" + '' + + (lib.optionalString patchVSCodePath '' # Override the previously determined VSCODE_PATH with the one we know to be correct sed -i "/ELECTRON=/iVSCODE_PATH='$out/lib/${libraryName}'" "$out/bin/${executableName}" grep -q "VSCODE_PATH='$out/lib/${libraryName}'" "$out/bin/${executableName}" # check if sed succeeded + '') + + '' # Remove native encryption code, as it derives the key from the executable path which does not work for us. # The credentials should be stored in a secure keychain already, so the benefit of this is questionable diff --git a/pkgs/by-name/co/code-cursor/package.nix b/pkgs/by-name/co/code-cursor/package.nix index f0c63faeff39e..8d00f27908a89 100644 --- a/pkgs/by-name/co/code-cursor/package.nix +++ b/pkgs/by-name/co/code-cursor/package.nix @@ -1,57 +1,18 @@ { lib, - stdenvNoCC, + stdenv, + callPackage, + vscode-generic, fetchurl, - - # build appimageTools, - - # linux dependencies - alsa-lib, - at-spi2-atk, - autoPatchelfHook, - cairo, - cups, - curlWithGnuTls, - egl-wayland, - expat, - fontconfig, - freetype, - ffmpeg, - glib, - glibc, - glibcLocales, - gtk3, - libappindicator-gtk3, - libdrm, - libgbm, - libGL, - libnotify, - libva-minimal, - libxkbcommon, - libxkbfile, - makeWrapper, - nspr, - nss, - pango, - pciutils, - pulseaudio, - vivaldi-ffmpeg-codecs, - vulkan-loader, - wayland, - - # linux installation - rsync, - commandLineArgs ? "", - - # darwin build undmg, + commandLineArgs ? "", + useVSCodeRipgrep ? stdenv.hostPlatform.isDarwin, }: -let - pname = "cursor"; - version = "1.0.0"; - inherit (stdenvNoCC) hostPlatform; +let + inherit (stdenv) hostPlatform; + finalCommandLineArgs = "--update=false " + commandLineArgs; sources = { x86_64-linux = fetchurl { @@ -73,115 +34,47 @@ let }; source = sources.${hostPlatform.system}; - - # Linux -- build from AppImage - appimageContents = appimageTools.extractType2 { - inherit version pname; - src = source; - }; - - wrappedAppimage = appimageTools.wrapType2 { - inherit version pname; - src = source; - }; - in -stdenvNoCC.mkDerivation { - inherit pname version; - - src = if hostPlatform.isLinux then wrappedAppimage else source; - - nativeBuildInputs = - lib.optionals hostPlatform.isLinux [ - autoPatchelfHook - glibcLocales - makeWrapper - rsync - ] - ++ lib.optionals hostPlatform.isDarwin [ undmg ]; - - buildInputs = lib.optionals hostPlatform.isLinux [ - alsa-lib - at-spi2-atk - cairo - cups - curlWithGnuTls - egl-wayland - expat - ffmpeg - glib - gtk3 - libdrm - libgbm - libGL - libva-minimal - libxkbcommon - libxkbfile - nspr - nss - pango - pulseaudio - vivaldi-ffmpeg-codecs - vulkan-loader - wayland - ]; +(callPackage vscode-generic rec { + inherit useVSCodeRipgrep; + commandLineArgs = finalCommandLineArgs; - runtimeDependencies = lib.optionals hostPlatform.isLinux [ - egl-wayland - ffmpeg - glibc - libappindicator-gtk3 - libnotify - libxkbfile - pciutils - pulseaudio - wayland - fontconfig - freetype - ]; - - sourceRoot = lib.optionalString hostPlatform.isDarwin "."; - - # Don't break code signing - dontUpdateAutotoolsGnuConfigScripts = hostPlatform.isDarwin; - dontConfigure = hostPlatform.isDarwin; - dontFixup = hostPlatform.isDarwin; + version = "1.0.0"; + pname = "cursor"; - installPhase = '' - runHook preInstall - mkdir -p $out/ + # You can find the current VSCode version in the About dialog: + # workbench.action.showAboutDialog (Help: About) + vscodeVersion = "1.96.2"; - ${lib.optionalString hostPlatform.isLinux '' - cp -r bin $out/bin - # mkdir -p $out/share/cursor - # cp -ar ${appimageContents}/usr/share $out/ + executableName = "cursor"; + longName = "Cursor"; + shortName = "cursor"; + libraryName = "cursor"; + iconName = "cursor"; - rsync -a -q ${appimageContents}/usr/share $out/ --exclude "*.so" + src = + if hostPlatform.isLinux then + appimageTools.extract { + inherit pname version; + src = source; + } + else + source; - # Fix the desktop file to point to the correct location - substituteInPlace $out/share/applications/cursor.desktop --replace-fail "/usr/share/cursor/cursor" "$out/bin/cursor" + sourceRoot = + if hostPlatform.isLinux then "${pname}-${version}-extracted/usr/share/cursor" else "Cursor.app"; - wrapProgram $out/bin/cursor \ - --add-flags "--update=false" \ - --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}} --no-update" \ - --add-flags ${lib.escapeShellArg commandLineArgs} - ''} + tests = { }; - ${lib.optionalString hostPlatform.isDarwin '' - APP_DIR="$out/Applications" - mkdir -p "$APP_DIR" - cp -Rp Cursor.app "$APP_DIR" - mkdir -p "$out/bin" - ln -s "$APP_DIR/Cursor.app/Contents/Resources/app/bin/cursor" "$out/bin/cursor" - ''} + updateScript = ./update.sh; - runHook postInstall - ''; + # Editing the `cursor` binary within the app bundle causes the bundle's signature + # to be invalidated, which prevents launching starting with macOS Ventura, because Cursor is notarized. + # See https://eclecticlight.co/2022/06/17/app-security-changes-coming-in-ventura/ for more information. + dontFixup = stdenv.hostPlatform.isDarwin; - passthru = { - inherit sources; - updateScript = ./update.sh; - }; + # Cursor has no wrapper script. + patchVSCodePath = false; meta = { description = "AI-powered code editor built on vscode"; @@ -196,4 +89,20 @@ stdenvNoCC.mkDerivation { platforms = lib.platforms.linux ++ lib.platforms.darwin; mainProgram = "cursor"; }; -} +}).overrideAttrs + (oldAttrs: { + nativeBuildInputs = + (oldAttrs.nativeBuildInputs or [ ]) + ++ lib.optionals hostPlatform.isDarwin [ undmg ]; + + preInstall = + (oldAttrs.preInstall or "") + + lib.optionalString hostPlatform.isLinux '' + mkdir -p bin + ln -s ../cursor bin/cursor + ''; + + passthru = (oldAttrs.passthru or { }) // { + inherit sources; + }; + }) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 30764abf51314..664c467cc8f08 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -14408,6 +14408,12 @@ with pkgs; vscodium-fhs = vscodium.fhs; vscodium-fhsWithPackages = vscodium.fhsWithPackages; + code-cursor = callPackage ../by-name/co/code-cursor/package.nix { + vscode-generic = ../applications/editors/vscode/generic.nix; + }; + code-cursor-fhs = code-cursor.fhs; + code-cursor-fhsWithPackages = code-cursor.fhsWithPackages; + windsurf = callPackage ../by-name/wi/windsurf/package.nix { vscode-generic = ../applications/editors/vscode/generic.nix; }; From 5cfcf8915266dd68e7b5d17aedab212fa1c6e1ec Mon Sep 17 00:00:00 2001 From: Kamil Monicz Date: Fri, 13 Jun 2025 14:45:32 +0200 Subject: [PATCH 2/2] code-cursor: specify linux platforms explicitly Co-authored-by: Masum Reza <50095635+JohnRTitor@users.noreply.github.com> --- pkgs/by-name/co/code-cursor/package.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/co/code-cursor/package.nix b/pkgs/by-name/co/code-cursor/package.nix index 8d00f27908a89..ec80caef8762f 100644 --- a/pkgs/by-name/co/code-cursor/package.nix +++ b/pkgs/by-name/co/code-cursor/package.nix @@ -86,7 +86,10 @@ in aspauldingcode prince213 ]; - platforms = lib.platforms.linux ++ lib.platforms.darwin; + platforms = [ + "aarch64-linux" + "x86_64-linux" + ] ++ lib.platforms.darwin; mainProgram = "cursor"; }; }).overrideAttrs