1{
2 lib,
3 stdenv,
4 makeWrapper,
5 fetchurl,
6 fetchzip,
7 wrapGAppsHook3,
8 glib,
9 gtk3,
10 gtk4,
11 unzip,
12 at-spi2-atk,
13 libdrm,
14 libgbm,
15 libxkbcommon,
16 libxshmfence,
17 libGL,
18 vulkan-loader,
19 alsa-lib,
20 cairo,
21 cups,
22 dbus,
23 expat,
24 gdk-pixbuf,
25 nss,
26 nspr,
27 xorg,
28 pango,
29 systemd,
30 pciutils,
31 libnotify,
32 pipewire,
33 libsecret,
34 libpulseaudio,
35 speechd-minimal,
36}:
37
38version: hashes:
39let
40 pname = "electron";
41
42 meta = with lib; {
43 description = "Cross platform desktop application shell";
44 homepage = "https://github.com/electron/electron";
45 license = licenses.mit;
46 mainProgram = "electron";
47 maintainers = with maintainers; [
48 yayayayaka
49 teutat3s
50 tomasajt
51 ];
52 platforms = [
53 "x86_64-darwin"
54 "x86_64-linux"
55 "armv7l-linux"
56 "aarch64-linux"
57 "aarch64-darwin"
58 ];
59 sourceProvenance = with sourceTypes; [ binaryNativeCode ];
60 # https://www.electronjs.org/docs/latest/tutorial/electron-timelines
61 knownVulnerabilities = optional (versionOlder version "36.0.0") "Electron version ${version} is EOL";
62 };
63
64 fetcher =
65 vers: tag: hash:
66 fetchurl {
67 url = "https://github.com/electron/electron/releases/download/v${vers}/electron-v${vers}-${tag}.zip";
68 sha256 = hash;
69 };
70
71 headersFetcher =
72 vers: hash:
73 fetchzip {
74 name = "electron-${vers}-headers";
75 url = "https://artifacts.electronjs.org/headers/dist/v${vers}/node-v${vers}-headers.tar.gz";
76 sha256 = hash;
77 };
78
79 tags = {
80 x86_64-linux = "linux-x64";
81 armv7l-linux = "linux-armv7l";
82 aarch64-linux = "linux-arm64";
83 x86_64-darwin = "darwin-x64";
84 aarch64-darwin = "darwin-arm64";
85 };
86
87 get = as: platform: as.${platform.system} or (throw "Unsupported system: ${platform.system}");
88
89 common = platform: {
90 inherit pname version meta;
91 src = fetcher version (get tags platform) (get hashes platform);
92 passthru.headers = headersFetcher version hashes.headers;
93 };
94
95 electronLibPath = lib.makeLibraryPath [
96 alsa-lib
97 at-spi2-atk
98 cairo
99 cups
100 dbus
101 expat
102 gdk-pixbuf
103 glib
104 gtk3
105 gtk4
106 nss
107 nspr
108 xorg.libX11
109 xorg.libxcb
110 xorg.libXcomposite
111 xorg.libXdamage
112 xorg.libXext
113 xorg.libXfixes
114 xorg.libXrandr
115 xorg.libxkbfile
116 pango
117 pciutils
118 stdenv.cc.cc
119 systemd
120 libnotify
121 pipewire
122 libsecret
123 libpulseaudio
124 speechd-minimal
125 libdrm
126 libgbm
127 libxkbcommon
128 libxshmfence
129 libGL
130 vulkan-loader
131 ];
132
133 linux = finalAttrs: {
134 buildInputs = [
135 glib
136 gtk3
137 gtk4
138 ];
139
140 nativeBuildInputs = [
141 unzip
142 makeWrapper
143 wrapGAppsHook3
144 ];
145
146 dontUnpack = true;
147 dontBuild = true;
148
149 installPhase = ''
150 mkdir -p $out/libexec/electron
151 unzip -d $out/libexec/electron $src
152 chmod u-x $out/libexec/electron/*.so*
153 '';
154
155 # We don't want to wrap the contents of $out/libexec automatically
156 dontWrapGApps = true;
157
158 preFixup = ''
159 makeWrapper "$out/libexec/electron/electron" $out/bin/electron \
160 "''${gappsWrapperArgs[@]}"
161 '';
162
163 postFixup = ''
164 patchelf \
165 --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
166 --set-rpath "${electronLibPath}:$out/libexec/electron" \
167 $out/libexec/electron/electron \
168 $out/libexec/electron/chrome_crashpad_handler
169
170 # patch libANGLE
171 patchelf \
172 --set-rpath "${
173 lib.makeLibraryPath [
174 libGL
175 pciutils
176 vulkan-loader
177 ]
178 }" \
179 $out/libexec/electron/lib*GL*
180
181 # replace bundled vulkan-loader
182 rm "$out/libexec/electron/libvulkan.so.1"
183 ln -s -t "$out/libexec/electron" "${lib.getLib vulkan-loader}/lib/libvulkan.so.1"
184 '';
185
186 passthru.dist = finalAttrs.finalPackage + "/libexec/electron";
187 };
188
189 darwin = finalAttrs: {
190 nativeBuildInputs = [
191 makeWrapper
192 unzip
193 ];
194
195 buildCommand = ''
196 mkdir -p $out/Applications
197 unzip $src
198 mv Electron.app $out/Applications
199 mkdir -p $out/bin
200 makeWrapper $out/Applications/Electron.app/Contents/MacOS/Electron $out/bin/electron
201 '';
202
203 passthru.dist = finalAttrs.finalPackage + "/Applications";
204 };
205in
206stdenv.mkDerivation (
207 finalAttrs:
208 lib.recursiveUpdate (common stdenv.hostPlatform) (
209 (if stdenv.hostPlatform.isDarwin then darwin else linux) finalAttrs
210 )
211)