nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 181 lines 5.8 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchFromGitHub, 5 makeWrapper, 6 makeDesktopItem, 7 nodejs, 8 electron_39, 9 element-web, 10 sqlcipher, 11 callPackage, 12 typescript, 13 # command line arguments which are always set 14 commandLineArgs ? "", 15 yarnConfigHook, 16 yarnBuildHook, 17 fetchYarnDeps, 18 asar, 19 copyDesktopItems, 20 darwin, 21}: 22 23let 24 pinData = import ./element-desktop-pin.nix; 25 inherit (pinData.hashes) desktopSrcHash desktopYarnHash; 26 executableName = "element-desktop"; 27 electron = electron_39; 28 seshat = callPackage ./seshat { }; 29in 30stdenv.mkDerivation ( 31 finalAttrs: 32 removeAttrs pinData [ "hashes" ] 33 // { 34 pname = "element-desktop"; 35 name = "${finalAttrs.pname}-${finalAttrs.version}"; 36 src = fetchFromGitHub { 37 owner = "element-hq"; 38 repo = "element-desktop"; 39 rev = "v${finalAttrs.version}"; 40 hash = desktopSrcHash; 41 }; 42 43 offlineCache = fetchYarnDeps { 44 yarnLock = finalAttrs.src + "/yarn.lock"; 45 hash = desktopYarnHash; 46 }; 47 48 env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1"; 49 50 nativeBuildInputs = [ 51 asar 52 copyDesktopItems 53 nodejs 54 makeWrapper 55 typescript 56 yarnConfigHook 57 yarnBuildHook 58 ] 59 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 60 darwin.autoSignDarwinBinariesHook 61 ]; 62 63 inherit seshat; 64 65 # Only affects unused scripts in $out/share/element/electron/scripts. Also 66 # breaks because there are some `node`-scripts with a `npx`-shebang and 67 # this shouldn't be in the closure just for unused scripts. 68 dontPatchShebangs = true; 69 70 postPatch = '' 71 cp -r ${electron.dist} electron-dist 72 chmod -R u+w electron-dist 73 74 substituteInPlace package.json \ 75 --replace-fail \ 76 ' electron-builder",' \ 77 ' electron-builder --dir -c.electronDist=electron-dist -c.electronVersion=${electron.version} -c.mac.identity=null",' 78 79 # `@electron/fuses` tries to run `codesign` and fails. Disable and use autoSignDarwinBinariesHook instead 80 substituteInPlace ./electron-builder.ts \ 81 --replace-fail "resetAdHocDarwinSignature:" "// resetAdHocDarwinSignature:" 82 83 # Need to disable asar integrity check to copy in native seshat files, see postBuild phase 84 substituteInPlace ./electron-builder.ts \ 85 --replace-fail "enableEmbeddedAsarIntegrityValidation: true" "enableEmbeddedAsarIntegrityValidation: false" 86 ''; 87 88 preBuild = '' 89 # Apply upstream patch 90 # Can be removed if upstream removes patches/@types+auto-launch+5.0.5.patch introduced in 91 # https://github.com/element-hq/element-desktop/commit/5e882f8e08d58bf9663c8e3ab33885bf7b3709de 92 node ./node_modules/patch-package/index.js 93 ''; 94 95 postBuild = '' 96 # relative path to app.asar differs on Linux and MacOS 97 packed=$(find ./dist -name app.asar) 98 asar extract "$packed" tmp-app 99 100 # linking here leads to Error: tmp-app/node_modules/matrix-seshat: file ... links out of the package 101 cp -r $seshat tmp-app/node_modules/matrix-seshat 102 103 asar pack tmp-app "$packed" 104 ''; 105 106 installPhase = '' 107 runHook preInstall 108 '' 109 + lib.optionalString stdenv.hostPlatform.isDarwin '' 110 mkdir -p "$out/Applications" "$out/bin" 111 mv dist/mac*/Element.app "$out/Applications" 112 113 ln -s '${element-web}' "$out/Applications/Element.app/Contents/Resources/webapp" 114 115 wrapProgram "$out/Applications/Element.app/Contents/MacOS/Element" \ 116 --add-flags ${lib.escapeShellArg commandLineArgs} 117 118 makeWrapper "$out/Applications/Element.app/Contents/MacOS/Element" "$out/bin/${executableName}" 119 '' 120 + lib.optionalString (!stdenv.hostPlatform.isDarwin) '' 121 mkdir -p "$out/bin" "$out/share" 122 123 cp -a dist/*-unpacked/resources $out/share/element 124 125 ln -s '${element-web}' "$out/share/element/webapp" 126 127 # icon, used in makeDesktopItem 128 mkdir -p "$out/share/icons/hicolor/512x512/apps" 129 ln -s "$out/share/element/build/icon.png" "$out/share/icons/hicolor/512x512/apps/element.png" 130 131 # executable wrapper 132 # LD_PRELOAD workaround for sqlcipher not found: https://github.com/matrix-org/seshat/issues/102 133 makeWrapper '${lib.getExe electron}' "$out/bin/${executableName}" \ 134 --set LD_PRELOAD ${sqlcipher}/lib/libsqlcipher.so \ 135 --add-flags "$out/share/element/app.asar" \ 136 --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}" \ 137 --add-flags ${lib.escapeShellArg commandLineArgs} 138 '' 139 + '' 140 runHook postInstall 141 ''; 142 143 # The desktop item properties should be kept in sync with data from upstream: 144 # https://github.com/element-hq/element-desktop/blob/develop/package.json 145 desktopItems = [ 146 (makeDesktopItem { 147 name = "element-desktop"; 148 exec = "${executableName} %u"; 149 icon = "element"; 150 desktopName = "Element"; 151 genericName = "Matrix Client"; 152 comment = finalAttrs.meta.description; 153 categories = [ 154 "Network" 155 "InstantMessaging" 156 "Chat" 157 ]; 158 startupWMClass = "Element"; 159 mimeTypes = [ 160 "x-scheme-handler/element" 161 "x-scheme-handler/io.element.desktop" 162 ]; 163 }) 164 ]; 165 166 passthru = { 167 # run with: nix-shell ./maintainers/scripts/update.nix --argstr package element-desktop 168 updateScript = ./update.sh; 169 }; 170 171 meta = { 172 description = "Feature-rich client for Matrix.org"; 173 homepage = "https://element.io/"; 174 changelog = "https://github.com/element-hq/element-desktop/blob/v${finalAttrs.version}/CHANGELOG.md"; 175 license = lib.licenses.agpl3Plus; 176 teams = [ lib.teams.matrix ]; 177 inherit (electron.meta) platforms; 178 mainProgram = "element-desktop"; 179 }; 180 } 181)