lol
1{ lib, stdenv
2, libXScrnSaver
3, makeWrapper
4, fetchurl
5, wrapGAppsHook
6, glib
7, gtk3
8, unzip
9, atomEnv
10, libuuid
11, at-spi2-atk
12, at-spi2-core
13, libdrm
14, mesa
15, libxkbcommon
16, libappindicator-gtk3
17, libxshmfence
18, libglvnd
19}:
20
21version: hashes:
22let
23 pname = "electron";
24
25 meta = with lib; {
26 description = "Cross platform desktop application shell";
27 homepage = "https://github.com/electron/electron";
28 license = licenses.mit;
29 maintainers = with maintainers; [ travisbhartwell manveru prusnak ];
30 platforms = [ "x86_64-darwin" "x86_64-linux" "armv7l-linux" "aarch64-linux" ]
31 ++ optionals (versionAtLeast version "11.0.0") [ "aarch64-darwin" ]
32 ++ optionals (versionOlder version "19.0.0") [ "i686-linux" ];
33 sourceProvenance = with sourceTypes; [ binaryNativeCode ];
34 knownVulnerabilities = optional (versionOlder version "18.0.0") "Electron version ${version} is EOL";
35 };
36
37 fetcher = vers: tag: hash: fetchurl {
38 url = "https://github.com/electron/electron/releases/download/v${vers}/electron-v${vers}-${tag}.zip";
39 sha256 = hash;
40 };
41
42 headersFetcher = vers: hash: fetchurl {
43 url = "https://artifacts.electronjs.org/headers/dist/v${vers}/node-v${vers}-headers.tar.gz";
44 sha256 = hash;
45 };
46
47 tags = {
48 x86_64-linux = "linux-x64";
49 armv7l-linux = "linux-armv7l";
50 aarch64-linux = "linux-arm64";
51 x86_64-darwin = "darwin-x64";
52 } // lib.optionalAttrs (lib.versionAtLeast version "11.0.0") {
53 aarch64-darwin = "darwin-arm64";
54 } // lib.optionalAttrs (lib.versionOlder version "19.0.0") {
55 i686-linux = "linux-ia32";
56 };
57
58 get = as: platform: as.${platform.system} or (throw "Unsupported system: ${platform.system}");
59
60 common = platform: {
61 inherit pname version meta;
62 src = fetcher version (get tags platform) (get hashes platform);
63 passthru.headers = headersFetcher version hashes.headers;
64 };
65
66 electronLibPath = with lib; makeLibraryPath (
67 [ libuuid at-spi2-atk at-spi2-core libappindicator-gtk3 ]
68 ++ optionals (versionAtLeast version "9.0.0") [ libdrm mesa ]
69 ++ optionals (versionOlder version "10.0.0") [ libXScrnSaver ]
70 ++ optionals (versionAtLeast version "11.0.0") [ libxkbcommon ]
71 ++ optionals (versionAtLeast version "12.0.0") [ libxshmfence ]
72 ++ optionals (versionAtLeast version "17.0.0") [ libglvnd ]
73 );
74
75 linux = {
76 buildInputs = [ glib gtk3 ];
77
78 nativeBuildInputs = [
79 unzip
80 makeWrapper
81 wrapGAppsHook
82 ];
83
84 dontWrapGApps = true; # electron is in lib, we need to wrap it manually
85
86 dontUnpack = true;
87 dontBuild = true;
88
89 installPhase = ''
90 mkdir -p $out/lib/electron $out/bin
91 unzip -d $out/lib/electron $src
92 ln -s $out/lib/electron/electron $out/bin
93 '';
94
95 postFixup = ''
96 patchelf \
97 --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
98 --set-rpath "${atomEnv.libPath}:${electronLibPath}:$out/lib/electron" \
99 $out/lib/electron/electron \
100 ${lib.optionalString (lib.versionAtLeast version "15.0.0") "$out/lib/electron/chrome_crashpad_handler" }
101
102 wrapProgram $out/lib/electron/electron "''${gappsWrapperArgs[@]}"
103 '';
104 };
105
106 darwin = {
107 nativeBuildInputs = [
108 makeWrapper
109 unzip
110 ];
111
112 buildCommand = ''
113 mkdir -p $out/Applications
114 unzip $src
115 mv Electron.app $out/Applications
116 mkdir -p $out/bin
117 makeWrapper $out/Applications/Electron.app/Contents/MacOS/Electron $out/bin/electron
118 '';
119 };
120in
121 stdenv.mkDerivation (
122 (common stdenv.hostPlatform) //
123 (if stdenv.isDarwin then darwin else linux)
124 )