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