1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 jetbrains,
6 openjdk17,
7 openjdk17-bootstrap,
8 git,
9 autoconf,
10 unzip,
11 rsync,
12 debugBuild ? false,
13 withJcef ? true,
14
15 libXdamage,
16 libXxf86vm,
17 libXrandr,
18 libXi,
19 libXcursor,
20 libXrender,
21 libX11,
22 libXext,
23 libxcb,
24 nss,
25 nspr,
26 libdrm,
27 libgbm,
28 wayland,
29 udev,
30 fontconfig,
31}:
32
33assert debugBuild -> withJcef;
34
35let
36 arch =
37 {
38 "aarch64-linux" = "aarch64";
39 "x86_64-linux" = "x64";
40 }
41 .${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
42 cpu = stdenv.hostPlatform.parsed.cpu.name;
43in
44openjdk17.overrideAttrs (oldAttrs: rec {
45 pname = "jetbrains-jdk" + lib.optionalString withJcef "-jcef";
46 javaVersion = "17.0.15";
47 build = "1381";
48 # To get the new tag:
49 # git clone https://github.com/jetbrains/jetbrainsruntime
50 # cd jetbrainsruntime
51 # git tag --points-at [revision]
52 # Look for the line that starts with jbr-
53 openjdkTag = "jbr-17.0.15+6";
54 version = "${javaVersion}-b${build}";
55
56 src = fetchFromGitHub {
57 owner = "JetBrains";
58 repo = "JetBrainsRuntime";
59 rev = "jb${version}";
60 hash = "sha256-Ckv2SNugHK75Af+ZzI91+QodOHIa5TMcjVQYsO45mQo=";
61 };
62
63 env = {
64 BOOT_JDK = openjdk17-bootstrap.home;
65 # run `git log -1 --pretty=%ct` in jdk repo for new value on update
66 SOURCE_DATE_EPOCH = 1745907200;
67 };
68
69 patches = [ ];
70
71 dontConfigure = true;
72
73 buildPhase = ''
74 runHook preBuild
75
76 ${lib.optionalString withJcef "cp -r ${jetbrains.jcef} jcef_linux_${arch}"}
77
78 sed \
79 -e "s/OPENJDK_TAG=.*/OPENJDK_TAG=${openjdkTag}/" \
80 -e "s/SOURCE_DATE_EPOCH=.*//" \
81 -e "s/export SOURCE_DATE_EPOCH//" \
82 -i jb/project/tools/common/scripts/common.sh
83 substituteInPlace jb/project/tools/linux/scripts/mkimages_${arch}.sh --replace-fail "STATIC_CONF_ARGS" "STATIC_CONF_ARGS ''${configureFlags[*]}"
84 sed \
85 -e "s/create_image_bundle \"jb/#/" \
86 -e "s/echo Creating /exit 0 #/" \
87 -i jb/project/tools/linux/scripts/mkimages_${arch}.sh
88
89 patchShebangs .
90 ./jb/project/tools/linux/scripts/mkimages_${arch}.sh ${build} ${
91 if debugBuild then "fd" else (if withJcef then "jcef" else "nomod")
92 }
93
94 runHook postBuild
95 '';
96
97 installPhase =
98 let
99 buildType = if debugBuild then "fastdebug" else "release";
100 debugSuffix = if debugBuild then "-fastdebug" else "";
101 jcefSuffix = if debugBuild || !withJcef then "" else "_jcef";
102 jbrsdkDir = "jbrsdk${jcefSuffix}-${javaVersion}-linux-${arch}${debugSuffix}-b${build}";
103 in
104 ''
105 runHook preInstall
106
107 mv build/linux-${cpu}-server-${buildType}/images/jdk/man build/linux-${cpu}-server-${buildType}/images/${jbrsdkDir}
108 rm -rf build/linux-${cpu}-server-${buildType}/images/jdk
109 mv build/linux-${cpu}-server-${buildType}/images/${jbrsdkDir} build/linux-${cpu}-server-${buildType}/images/jdk
110 ''
111 + oldAttrs.installPhase
112 + "runHook postInstall";
113
114 postInstall = lib.optionalString withJcef ''
115 chmod +x $out/lib/openjdk/lib/chrome-sandbox
116 '';
117
118 dontStrip = debugBuild;
119
120 postFixup = ''
121 # Build the set of output library directories to rpath against
122 LIBDIRS="${
123 lib.makeLibraryPath [
124 libXdamage
125 libXxf86vm
126 libXrandr
127 libXi
128 libXcursor
129 libXrender
130 libX11
131 libXext
132 libxcb
133 nss
134 nspr
135 libdrm
136 libgbm
137 wayland
138 udev
139 fontconfig
140 ]
141 }"
142 for output in ${lib.concatStringsSep " " oldAttrs.outputs}; do
143 if [ "$output" = debug ]; then continue; fi
144 LIBDIRS="$(find $(eval echo \$$output) -name \*.so\* -exec dirname {} \+ | sort -u | tr '\n' ':'):$LIBDIRS"
145 done
146 # Add the local library paths to remove dependencies on the bootstrap
147 for output in ${lib.concatStringsSep " " oldAttrs.outputs}; do
148 if [ "$output" = debug ]; then continue; fi
149 OUTPUTDIR=$(eval echo \$$output)
150 BINLIBS=$(find $OUTPUTDIR/bin/ -type f; find $OUTPUTDIR -name \*.so\*)
151 echo "$BINLIBS" | while read i; do
152 patchelf --set-rpath "$LIBDIRS:$(patchelf --print-rpath "$i")" "$i" || true
153 done
154 done
155 '';
156
157 nativeBuildInputs = [
158 git
159 autoconf
160 unzip
161 rsync
162 ]
163 ++ oldAttrs.nativeBuildInputs;
164
165 meta = with lib; {
166 description = "OpenJDK fork which better supports Jetbrains's products";
167 longDescription = ''
168 JetBrains Runtime is a runtime environment for running IntelliJ Platform
169 based products on Windows, Mac OS X, and Linux. JetBrains Runtime is
170 based on OpenJDK project with some modifications. These modifications
171 include: Subpixel Anti-Aliasing, enhanced font rendering on Linux, HiDPI
172 support, ligatures, some fixes for native crashes not presented in
173 official build, and other small enhancements.
174 JetBrains Runtime is not a certified build of OpenJDK. Please, use at
175 your own risk.
176 '';
177 homepage = "https://confluence.jetbrains.com/display/JBR/JetBrains+Runtime";
178 inherit (openjdk17.meta) license platforms mainProgram;
179 maintainers = with maintainers; [ edwtjo ];
180
181 broken = stdenv.hostPlatform.isDarwin;
182 };
183
184 passthru = oldAttrs.passthru // {
185 home = "${jetbrains.jdk}/lib/openjdk";
186 };
187})