This repository was archived by the owner on Dec 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathflake.nix
More file actions
207 lines (182 loc) · 8.55 KB
/
Copy pathflake.nix
File metadata and controls
207 lines (182 loc) · 8.55 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
{
description = "Flake for building Cursor on Linux ARM and Windows ARM platforms";
inputs = {
# Pinned to align the version of VS Codium with Cursor's build.
nixpkgs.url = "github:NixOS/nixpkgs/212defe037698e18fc9521dfe451779a8979844c";
};
outputs = { self, nixpkgs }:
let
supportedSystems = [ "aarch64-linux" "armv7l-linux" "x86_64-linux" ];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
in
{
packages = forAllSystems (system:
let
pkgs = import nixpkgs { inherit system; };
# It's difficult to find pinned versions of Cursor.
# The latest version and download URL were found here:
# https://changelog.cursor.sh/
cursorVersion = "0.44.0";
# This is the VS Code version that Cursor was built on.
vscodeVersion = "1.93.1";
cursorSrc = pkgs.appimageTools.extractType2 {
pname = "cursor-appimage";
version = cursorVersion;
src = pkgs.fetchurl {
url = "https://dl.todesktop.com/230313mzl4w4u92/versions/${cursorVersion}/linux/appImage/x64";
sha256 = "sha256-jM2VKg9Zx4sNqWtNgdBiiV84T5KkyExi0K/7P/uiD30=";
};
};
vscodeLinuxArm64 = builtins.fetchTarball {
url = "https://update.code.visualstudio.com/${vscodeVersion}/linux-arm64/stable";
sha256 = "sha256:041bkfbrf1nxq1fr9745h70ky8i3jby8kgihpaf5pwp5cbvzbsnw";
};
vscodeLinuxArm32 = builtins.fetchTarball {
url = "https://update.code.visualstudio.com/${vscodeVersion}/linux-armhf/stable";
sha256 = "sha256:19lv6jk54zq8j9khb9ds819jc7x7izvamgkg7sqhaq891kjvvv4a";
};
vscodeWindowsArm64 = pkgs.fetchzip {
stripRoot = false;
url = "https://update.code.visualstudio.com/${vscodeVersion}/win32-arm64-archive/stable#file.zip";
sha256 = "sha256-vxTGt1qT/bxwb5DXPMxUBrFPuP5xnqXEYWkQMrKEeXI=";
};
# Copies Cursor-specific resources into the VS Code package.
copyCursorFiles = root: ''
cp -R ${cursorSrc}/resources/app/out ${root}/resources/app/
cp -R ${cursorSrc}/resources/app/*.json ${root}/resources/app/
cp -R ${cursorSrc}/resources/app/extensions/cursor-* ${root}/resources/app/extensions/
rm -rf "${root}/resources/app/node_modules"{,.asar}
cp -R ${cursorSrc}/resources/app/node_modules.asar ${root}/resources/app/
rm -rf ${root}/resources/app/resources
cp -R ${cursorSrc}/resources/app/resources ${root}/resources/app/
'';
artifactName = os: arch: ext: "cursor_${cursorVersion}_${os}_${arch}.${ext}";
# Overrides the VS Code package with Cursor's resources.
buildCursorNix = { vscodePackage }:
vscodePackage.overrideAttrs (oldAttrs: {
pname = "cursor";
version = cursorVersion;
executableName = "cursor";
postInstall = (oldAttrs.postInstall or "") + ''
${(copyCursorFiles "$out/lib/vscode")}
# Replace VS Code's icon and desktop file with Cursor's
cp ${cursorSrc}/cursor.png $out/share/pixmaps/cursor.png
# Rename the binary
mv $out/bin/code $out/bin/cursor || true
mv $out/bin/codium $out/bin/cursor || true
# Wrap the binary to disable no-new-privileges
mv $out/bin/cursor $out/bin/.cursor-wrapped
makeWrapper $out/bin/.cursor-wrapped $out/bin/cursor \
--set NO_NEW_PRIVILEGES "0"
'';
nativeBuildInputs = (oldAttrs.nativeBuildInputs or []) ++ [ pkgs.makeWrapper ];
meta = oldAttrs.meta // {
description = "Cursor ${cursorVersion}";
mainProgram = "cursor";
};
});
# Builds Cursor using a prepackaged set of VS Code files.
# This is for creating dynamically linked builds.
buildCursorPrepackaged = { vscodeFiles, name, isWindows ? false }:
pkgs.stdenv.mkDerivation {
pname = "cursor-${name}";
version = cursorVersion;
src = vscodeFiles;
dontPatchShebangs = true;
buildPhase = ''
cp -R --preserve=mode,timestamps . $out
${copyCursorFiles "$out"}
# Replace VS Code's icon and desktop file with Cursor's
cp ${cursorSrc}/cursor.png $out/cursor.png
cp ${cursorSrc}/cursor.desktop $out/cursor.desktop
cp -R ${cursorSrc}/resources/todesktop* $out/resources/
# This is excluded intentionally. It causes an error in console,
# but there's some token we must be missing?
# cp ${cursorSrc}/resources/app-update.yml $out/resources/
# Cursor doesn't have a root bin dir
rm -rf $out/bin
mv $out/code $out/cursor || true
mv $out/codium $out/cursor || true
mv $out/Code.exe $out/Cursor.exe || true
# Platform-specific adjustments
${if !isWindows then ''
cp -R ${cursorSrc}/usr $out
cp ${cursorSrc}/AppRun $out
cp ${cursorSrc}/.DirIcon $out
'' else ''
''}
'';
};
in
{
extract-vscode-version = pkgs.runCommand "extract-vscode-version" { } ''
${pkgs.jq}/bin/jq -r .vscodeVersion ${cursorSrc}/resources/app/product.json >> $out
'';
cursor = {
unpacked = cursorSrc;
linux = {
arm64 = buildCursorPrepackaged {
vscodeFiles = vscodeLinuxArm64;
name = "linux-arm64";
};
arm64-appimage = pkgs.stdenv.mkDerivation {
pname = artifactName "linux" "arm64" "AppImage";
version = cursorVersion;
src = self.packages.${system}.cursor.linux.arm64;
dontPatchShebangs = true;
buildInputs = [ pkgs.appimagekit ];
buildPhase = ''
mkdir -p $out
ARCH=arm_aarch64 appimagetool $src $out/${artifactName "linux" "arm64" "AppImage"}
chmod +x $out/${artifactName "linux" "arm64" "AppImage"}
patchelf --set-interpreter /lib/ld-linux-aarch64.so.1 $out/${artifactName "linux" "arm64" "AppImage"}
'';
};
arm64-targz = pkgs.runCommand "tarball" { } ''
mkdir -p $out
cd ${self.packages.${system}.cursor.linux.arm64}
${pkgs.gnutar}/bin/tar -czvf $out/${artifactName "linux" "arm64" "tar.gz"} .
'';
arm32 = buildCursorPrepackaged {
vscodeFiles = vscodeLinuxArm32;
name = "linux-arm32";
};
arm32-appimage = pkgs.stdenv.mkDerivation {
name = artifactName "linux" "arm32" "AppImage";
src = self.packages.${system}.cursor.linux.arm32;
dontPatchShebangs = true;
buildInputs = [ pkgs.appimagekit ];
buildPhase = ''
mkdir -p $out
ARCH=arm appimagetool $src $out/${artifactName "linux" "arm32" "AppImage"}
chmod +x $out/${artifactName "linux" "arm32" "AppImage"}
patchelf --set-interpreter /lib/ld-linux.so.3 $out/${artifactName "linux" "arm32" "AppImage"}
'';
};
arm32-targz = pkgs.runCommand "tarball" { } ''
mkdir -p $out
cd ${self.packages.${system}.cursor.linux.arm32}
${pkgs.gnutar}/bin/tar -czvf $out/${artifactName "linux" "arm32" "tar.gz"} .
'';
};
windows = {
arm64 = buildCursorPrepackaged {
vscodeFiles = vscodeWindowsArm64;
name = "windows-arm64";
isWindows = true;
};
arm64-zip = pkgs.runCommand "zip" { } ''
mkdir -p $out
cd ${self.packages.${system}.cursor.windows.arm64}
${pkgs.zip}/bin/zip -r $out/${artifactName "windows" "arm64" "zip"} .
'';
};
nix = buildCursorNix {
vscodePackage = pkgs.vscodium;
};
};
default = self.packages.${system}.cursor.nix;
}
);
};
}