at 24.05-pre 3.9 kB view raw
1{ lib 2, stdenv 3, libXScrnSaver 4, makeWrapper 5, fetchurl 6, wrapGAppsHook 7, glib 8, gtk3 9, unzip 10, at-spi2-atk 11, libdrm 12, mesa 13, libxkbcommon 14, libxshmfence 15, libglvnd 16, alsa-lib 17, cairo 18, cups 19, dbus 20, expat 21, gdk-pixbuf 22, nss 23, nspr 24, xorg 25, pango 26, systemd 27, pciutils 28}: 29 30version: hashes: 31let 32 pname = "electron"; 33 34 meta = with lib; { 35 description = "Cross platform desktop application shell"; 36 homepage = "https://github.com/electron/electron"; 37 license = licenses.mit; 38 maintainers = with maintainers; [ travisbhartwell manveru prusnak ]; 39 platforms = [ "x86_64-darwin" "x86_64-linux" "armv7l-linux" "aarch64-linux" ] 40 ++ optionals (versionAtLeast version "11.0.0") [ "aarch64-darwin" ] 41 ++ optionals (versionOlder version "19.0.0") [ "i686-linux" ]; 42 sourceProvenance = with sourceTypes; [ binaryNativeCode ]; 43 knownVulnerabilities = optional (versionOlder version "25.0.0") "Electron version ${version} is EOL"; 44 }; 45 46 fetcher = vers: tag: hash: fetchurl { 47 url = "https://github.com/electron/electron/releases/download/v${vers}/electron-v${vers}-${tag}.zip"; 48 sha256 = hash; 49 }; 50 51 headersFetcher = vers: hash: fetchurl { 52 url = "https://artifacts.electronjs.org/headers/dist/v${vers}/node-v${vers}-headers.tar.gz"; 53 sha256 = hash; 54 }; 55 56 tags = { 57 x86_64-linux = "linux-x64"; 58 armv7l-linux = "linux-armv7l"; 59 aarch64-linux = "linux-arm64"; 60 x86_64-darwin = "darwin-x64"; 61 } // lib.optionalAttrs (lib.versionAtLeast version "11.0.0") { 62 aarch64-darwin = "darwin-arm64"; 63 } // lib.optionalAttrs (lib.versionOlder version "19.0.0") { 64 i686-linux = "linux-ia32"; 65 }; 66 67 get = as: platform: as.${platform.system} or (throw "Unsupported system: ${platform.system}"); 68 69 common = platform: { 70 inherit pname version meta; 71 src = fetcher version (get tags platform) (get hashes platform); 72 passthru.headers = headersFetcher version hashes.headers; 73 }; 74 75 electronLibPath = lib.makeLibraryPath ([ 76 alsa-lib 77 at-spi2-atk 78 cairo 79 cups 80 dbus 81 expat 82 gdk-pixbuf 83 glib 84 gtk3 85 nss 86 nspr 87 xorg.libX11 88 xorg.libxcb 89 xorg.libXcomposite 90 xorg.libXdamage 91 xorg.libXext 92 xorg.libXfixes 93 xorg.libXrandr 94 xorg.libxkbfile 95 pango 96 pciutils 97 stdenv.cc.cc.lib 98 systemd 99 ] 100 ++ lib.optionals (lib.versionAtLeast version "9.0.0") [ libdrm mesa ] 101 ++ lib.optionals (lib.versionOlder version "10.0.0") [ libXScrnSaver ] 102 ++ lib.optionals (lib.versionAtLeast version "11.0.0") [ libxkbcommon ] 103 ++ lib.optionals (lib.versionAtLeast version "12.0.0") [ libxshmfence ] 104 ++ lib.optionals (lib.versionAtLeast version "17.0.0") [ libglvnd ] 105 ); 106 107 linux = { 108 buildInputs = [ glib gtk3 ]; 109 110 nativeBuildInputs = [ 111 unzip 112 makeWrapper 113 wrapGAppsHook 114 ]; 115 116 dontUnpack = true; 117 dontBuild = true; 118 119 installPhase = '' 120 mkdir -p $out/libexec/electron $out/bin 121 unzip -d $out/libexec/electron $src 122 ln -s $out/libexec/electron/electron $out/bin 123 chmod u-x $out/libexec/electron/*.so* 124 ''; 125 126 postFixup = '' 127 patchelf \ 128 --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ 129 --set-rpath "${electronLibPath}:$out/libexec/electron" \ 130 $out/libexec/electron/.electron-wrapped \ 131 ${lib.optionalString (lib.versionAtLeast version "15.0.0") "$out/libexec/electron/.chrome_crashpad_handler-wrapped" } 132 ''; 133 }; 134 135 darwin = { 136 nativeBuildInputs = [ 137 makeWrapper 138 unzip 139 ]; 140 141 buildCommand = '' 142 mkdir -p $out/Applications 143 unzip $src 144 mv Electron.app $out/Applications 145 mkdir -p $out/bin 146 makeWrapper $out/Applications/Electron.app/Contents/MacOS/Electron $out/bin/electron 147 ''; 148 }; 149in 150 stdenv.mkDerivation ( 151 (common stdenv.hostPlatform) // 152 (if stdenv.isDarwin then darwin else linux) 153 )