1{
2 fetchFromGitHub,
3 fetchurl,
4 fetchzip,
5 lib,
6 linkFarm,
7 makeWrapper,
8 runCommand,
9 stdenv,
10 stdenvNoCC,
11 rustPlatform,
12
13 ant,
14 cmake,
15 fsnotifier,
16 glib,
17 glibc,
18 jetbrains,
19 kotlin,
20 libdbusmenu,
21 maven,
22 p7zip,
23 pkg-config,
24 xorg,
25
26 version,
27 buildNumber,
28 buildType,
29 ideaHash,
30 androidHash,
31 jpsHash,
32 restarterHash,
33 mvnDeps,
34 repositories,
35 kotlin-jps-plugin,
36}:
37
38let
39 kotlin' = kotlin.overrideAttrs (oldAttrs: {
40 version = "2.1.10";
41 src = fetchurl {
42 url = oldAttrs.src.url;
43 sha256 = "sha256-xuniY2iJgo4ZyIEdWriQhiU4yJ3CoxAZVt/uPCqLprE=";
44 };
45 });
46
47 jbr = jetbrains.jdk-no-jcef-17;
48
49 ideaSrc = fetchFromGitHub {
50 owner = "jetbrains";
51 repo = "intellij-community";
52 rev = "${buildType}/${buildNumber}";
53 hash = ideaHash;
54 };
55
56 androidSrc = fetchFromGitHub {
57 owner = "jetbrains";
58 repo = "android";
59 rev = "${buildType}/${buildNumber}";
60 hash = androidHash;
61 };
62
63 src = runCommand "source" { } ''
64 cp -r ${ideaSrc} $out
65 chmod +w -R $out
66 cp -r ${androidSrc} $out/android
67 '';
68
69 libdbusmenu-jb = libdbusmenu.overrideAttrs (old: {
70 version = "jetbrains-fork";
71 src = fetchFromGitHub {
72 owner = "jetbrains";
73 repo = "libdbusmenu";
74 rev = "d8a49303f908a272e6670b7cee65a2ba7c447875";
75 hash = "sha256-u87ZgbfeCPJ0qG8gsom3gFaZxbS5NcHEodb0EVakk60=";
76 };
77 configureFlags = old.configureFlags ++ [
78 "--enable-static"
79 ];
80 installPhase = ''
81 runHook preInstall
82
83 mkdir -p $out/lib
84 cp libdbusmenu-glib/.libs/libdbusmenu-glib.a $out/lib
85
86 runHook postInstall
87 '';
88 });
89
90 libdbm = stdenv.mkDerivation {
91 pname = "libdbm";
92 version = buildNumber;
93 nativeBuildInputs = [
94 cmake
95 pkg-config
96 ];
97 buildInputs = [
98 glib
99 xorg.libX11
100 libdbusmenu
101 ];
102 inherit src;
103 sourceRoot = "${src.name}/native/LinuxGlobalMenu";
104 patches = [ ../patches/libdbm-headers.patch ];
105 postPatch = "cp ${libdbusmenu-jb}/lib/libdbusmenu-glib.a libdbusmenu-glib.a";
106 passthru.patched-libdbusmenu = libdbusmenu-jb;
107 installPhase = ''
108 runHook preInstall
109
110 mkdir -p $out/lib
111 mv libdbm.so $out/lib/libdbm.so
112
113 runHook postInstall
114 '';
115 };
116
117 restarter = rustPlatform.buildRustPackage {
118 pname = "restarter";
119 version = buildNumber;
120 inherit src;
121 sourceRoot = "${src.name}/native/restarter";
122
123 cargoHash = restarterHash;
124
125 # Allow static linking
126 buildInputs = [
127 glibc
128 glibc.static
129 ];
130 };
131
132 jpsRepo =
133 runCommand "jps-bootstrap-repository"
134 {
135 outputHashAlgo = "sha256";
136 outputHashMode = "recursive";
137 outputHash = jpsHash;
138 nativeBuildInputs = [
139 ant
140 jbr
141 ];
142 }
143 ''
144 ant -Duser.home=$out -Dbuild.dir=/build/tmp -f ${src}/platform/jps-bootstrap/jps-bootstrap-classpath.xml
145 find $out -type f \( \
146 -name \*.lastUpdated \
147 -o -name resolver-status.properties \
148 -o -name _remote.repositories \) \
149 -delete
150 '';
151
152 jps-bootstrap = stdenvNoCC.mkDerivation {
153 pname = "jps-bootstrap";
154 version = buildNumber;
155 inherit src;
156 sourceRoot = "${src.name}/platform/jps-bootstrap";
157 nativeBuildInputs = [
158 ant
159 makeWrapper
160 jbr
161 ];
162 patches = [ ../patches/kotlinc-path.patch ];
163 postPatch = "sed -i 's|KOTLIN_PATH_HERE|${kotlin'}|' src/main/java/org/jetbrains/jpsBootstrap/KotlinCompiler.kt";
164 buildPhase = ''
165 runHook preBuild
166
167 ant -Duser.home=${jpsRepo} -Dbuild.dir=/build/out -f jps-bootstrap-classpath.xml
168
169 runHook postBuild
170 '';
171 installPhase = ''
172 runHook preInstall
173
174 mkdir -p $out/share/java/
175 cp /build/out/jps-bootstrap.classes.jar $out/share/java/jps-bootstrap.jar
176 cp -r /build/out/jps-bootstrap.out.lib $out/share/java/jps-bootstrap-classpath
177 makeWrapper ${jbr}/bin/java $out/bin/jps-bootstrap \
178 --add-flags "-cp $out/share/java/jps-bootstrap-classpath/'*' org.jetbrains.jpsBootstrap.JpsBootstrapMain"
179
180 runHook postInstall
181 '';
182 };
183
184 artefactsJson = lib.importJSON mvnDeps;
185 mkRepoEntry = entry: {
186 name = ".m2/repository/" + entry.path;
187 path = fetchurl {
188 urls = builtins.map (url: "${url}/${entry.url}") repositories;
189 sha256 = entry.hash;
190 };
191 };
192 mvnRepo = linkFarm "intellij-deps" (map mkRepoEntry artefactsJson);
193
194 kotlin-jps-plugin-classpath =
195 let
196 repoUrl = "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-ide-plugin-dependencies";
197 groupId = builtins.replaceStrings [ "." ] [ "/" ] "org.jetbrains.kotlin";
198 artefactId = "kotlin-jps-plugin-classpath";
199 version = kotlin-jps-plugin.version;
200 in
201 fetchurl {
202 url =
203 repoUrl
204 + "/"
205 + groupId
206 + "/"
207 + artefactId
208 + "/"
209 + version
210 + "/"
211 + artefactId
212 + "-"
213 + version
214 + ".jar";
215 hash = kotlin-jps-plugin.hash;
216 };
217
218 targetClass =
219 if buildType == "pycharm" then
220 "intellij.pycharm.community.build"
221 else
222 "intellij.idea.community.build";
223 targetName =
224 if buildType == "pycharm" then
225 "PyCharmCommunityInstallersBuildTarget"
226 else
227 "OpenSourceCommunityInstallersBuildTarget";
228
229 xplat-launcher = fetchzip {
230 url = "https://cache-redirector.jetbrains.com/intellij-dependencies/org/jetbrains/intellij/deps/launcher/242.22926/launcher-242.22926.tar.gz";
231 hash = "sha256-ttrQZUbBvvyH1BSVt1yWOoD82WwRi/hkoRfrsdCjwTA=";
232 stripRoot = false;
233 };
234
235 brokenPlugins = fetchurl {
236 url = "https://web.archive.org/web/20250509141038/https://downloads.marketplace.jetbrains.com/files/brokenPlugins.json";
237 hash = "sha256-FzYANZSTasCdVEu9jLF1+2PEH8SadUddaIaec5vhKH8=";
238 };
239
240in
241stdenvNoCC.mkDerivation rec {
242 pname = "${buildType}-community";
243 inherit version buildNumber;
244 name = "${pname}-${version}.tar.gz";
245 inherit src;
246 nativeBuildInputs = [
247 p7zip
248 jbr
249 jps-bootstrap
250 ];
251 repo = mvnRepo;
252
253 patches = [
254 ../patches/no-download.patch
255 ../patches/disable-sbom-generation.patch
256 ../patches/bump-jackson-core-in-source.patch
257 ];
258
259 postPatch = ''
260 cp ${restarter}/bin/restarter bin/linux/amd64/restarter
261 cp ${fsnotifier}/bin/fsnotifier bin/linux/amd64/fsnotifier
262 cp ${libdbm}/lib/libdbm.so bin/linux/amd64/libdbm.so
263
264 substituteInPlace \
265 platform/build-scripts/src/org/jetbrains/intellij/build/kotlin/KotlinCompilerDependencyDownloader.kt \
266 --replace-fail 'JPS_PLUGIN_CLASSPATH_HERE' '${kotlin-jps-plugin-classpath}' \
267 --replace-fail 'KOTLIN_PATH_HERE' '${kotlin'}'
268 substituteInPlace \
269 platform/build-scripts/downloader/src/org/jetbrains/intellij/build/dependencies/JdkDownloader.kt \
270 --replace-fail 'JDK_PATH_HERE' '${jbr}/lib/openjdk'
271 substituteInPlace \
272 platform/build-scripts/src/org/jetbrains/intellij/build/impl/brokenPlugins.kt \
273 --replace-fail 'BROKEN_PLUGINS_HERE' '${brokenPlugins}'
274 substituteInPlace \
275 platform/build-scripts/src/org/jetbrains/intellij/build/impl/LinuxDistributionBuilder.kt \
276 --replace-fail 'XPLAT_LAUNCHER_PREBUILT_PATH_HERE' '${xplat-launcher}'
277 substituteInPlace \
278 build/deps/src/org/jetbrains/intellij/build/impl/BundledMavenDownloader.kt \
279 --replace-fail 'MAVEN_REPO_HERE' '${mvnRepo}/.m2/repository/' \
280 --replace-fail 'MAVEN_PATH_HERE' '${maven}/maven'
281
282 echo '${buildNumber}.SNAPSHOT' > build.txt
283 '';
284
285 configurePhase = ''
286 runHook preConfigure
287
288 ln -s "$repo"/.m2 /build/.m2
289 export JPS_BOOTSTRAP_COMMUNITY_HOME=/build/source
290 jps-bootstrap \
291 -Dbuild.number=${buildNumber} \
292 -Djps.kotlin.home=${kotlin'} \
293 -Dintellij.build.target.os=linux \
294 -Dintellij.build.target.arch=x64 \
295 -Dintellij.build.skip.build.steps=mac_artifacts,mac_dmg,mac_sit,windows_exe_installer,windows_sign,repair_utility_bundle_step,sources_archive \
296 -Dintellij.build.unix.snaps=false \
297 --java-argfile-target=java_argfile \
298 /build/source \
299 ${targetClass} \
300 ${targetName}
301
302 runHook postConfigure
303 '';
304 buildPhase = ''
305 runHook preBuild
306
307 java \
308 -Djps.kotlin.home=${kotlin'} \
309 "@java_argfile"
310
311 runHook postBuild
312 '';
313 installPhase = ''
314 runHook preInstall
315 mv out/*/artifacts/*-no-jbr.tar.gz $out
316 runHook postInstall
317 '';
318
319 passthru = {
320 inherit libdbm fsnotifier jps-bootstrap;
321 };
322}