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