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