summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/co/code-cursor/package.nix
blob: 419426e61a341ade6b2985ca1a358268757e6a12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
{
  lib,
  stdenv,
  buildVscode,
  fetchurl,
  appimageTools,
  undmg,
  commandLineArgs ? "",
  useVSCodeRipgrep ? stdenv.hostPlatform.isDarwin,
}:

let
  inherit (stdenv) hostPlatform;

  sourcesJson = lib.importJSON ./sources.json;
  sources = lib.mapAttrs (
    _: info:
    fetchurl {
      inherit (info) url hash;
    }
  ) sourcesJson.sources;

  source = sources.${hostPlatform.system};
in
(buildVscode rec {
  inherit commandLineArgs useVSCodeRipgrep;
  inherit (sourcesJson) version;
  # Cursor reports vscode >= 1.122 but still ships @vscode/ripgrep.
  # Capping the build-time vscodeVersion avoids modifying the notarized app bundle on Darwin.
  vscodeVersion =
    if lib.versionAtLeast sourcesJson.vscodeVersion "1.122.0" then
      "1.121.0"
    else
      sourcesJson.vscodeVersion;

  pname = "cursor";

  executableName = "cursor";
  longName = "Cursor";
  shortName = "cursor";
  libraryName = "cursor";
  iconName = "cursor";

  src =
    if hostPlatform.isLinux then
      appimageTools.extract {
        inherit pname version;
        src = source;
      }
    else
      source;

  # for unpacking the DMG
  extraNativeBuildInputs = lib.optionals hostPlatform.isDarwin [ undmg ];

  sourceRoot =
    if hostPlatform.isLinux then "${pname}-${version}-extracted/usr/share/cursor" else "Cursor.app";

  tests = { };

  updateScript = ./update.sh;

  # 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;

  # Cursor ships a launcher script that resolves its own VSCODE_PATH.
  patchVSCodePath = false;

  meta = {
    description = "AI-powered code editor built on vscode";
    homepage = "https://cursor.com";
    changelog = "https://cursor.com/changelog";
    license = lib.licenses.unfree;
    sourceProvenance = [ lib.sourceTypes.binaryNativeCode ];
    maintainers = with lib.maintainers; [
      aspauldingcode
      prince213
      qweered
    ];
    platforms = [
      "aarch64-linux"
      "x86_64-linux"
    ]
    ++ lib.platforms.darwin;
    mainProgram = "cursor";
  };
}).overrideAttrs
  (oldAttrs: {
    autoPatchelfIgnoreMissingDeps =
      (oldAttrs.autoPatchelfIgnoreMissingDeps or [ ])
      ++ lib.optionals (stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isMusl) [
        "libc.musl-*.so.*" # musl-based node modules are not used on glibc systems
      ];

    preFixup =
      (oldAttrs.preFixup or "")
      + lib.optionalString hostPlatform.isLinux ''
        sed -i '/^Keywords=/a MimeType=application/x-cursor-workspace;' \
          $out/share/applications/cursor.desktop
      '';
    postInstall =
      (oldAttrs.postInstall or "")
      + lib.optionalString hostPlatform.isLinux ''
        install -Dm644 ../mime/packages/cursor-workspace.xml -t $out/share/mime/packages
        rm -f $out/lib/cursor/resources/appimageupdatetool.AppImage
      '';
  })