biglybt: 3.5.0.0 -> 3.6.0.0
[NixPkgs.git] / pkgs / applications / networking / instant-messengers / element / element-desktop.nix
blobdb8a8be7a87187f46d84218172b9fbe4fe9c9dd2
1 { lib
2 , stdenv
3 , fetchFromGitHub
4 , makeWrapper
5 , makeDesktopItem
6 , fixup-yarn-lock
7 , yarn
8 , nodejs
9 , fetchYarnDeps
10 , jq
11 , electron
12 , element-web
13 , sqlcipher
14 , callPackage
15 , Security
16 , AppKit
17 , CoreServices
18 , desktopToDarwinBundle
19 , useKeytar ? true
22 let
23   pinData = import ./pin.nix;
24   inherit (pinData.hashes) desktopSrcHash desktopYarnHash;
25   executableName = "element-desktop";
26   keytar = callPackage ./keytar { inherit Security AppKit; };
27   seshat = callPackage ./seshat { inherit CoreServices; };
29 stdenv.mkDerivation (finalAttrs: builtins.removeAttrs pinData [ "hashes" ] // {
30   pname = "element-desktop";
31   name = "${finalAttrs.pname}-${finalAttrs.version}";
32   src = fetchFromGitHub {
33     owner = "vector-im";
34     repo = "element-desktop";
35     rev = "v${finalAttrs.version}";
36     hash = desktopSrcHash;
37   };
39   offlineCache = fetchYarnDeps {
40     yarnLock = finalAttrs.src + "/yarn.lock";
41     sha256 = desktopYarnHash;
42   };
44   nativeBuildInputs = [ yarn fixup-yarn-lock nodejs makeWrapper jq ]
45     ++ lib.optionals stdenv.isDarwin [ desktopToDarwinBundle ];
47   inherit seshat;
49   configurePhase = ''
50     runHook preConfigure
52     export HOME=$(mktemp -d)
53     yarn config --offline set yarn-offline-mirror $offlineCache
54     fixup-yarn-lock yarn.lock
55     yarn install --offline --frozen-lockfile --ignore-platform --ignore-scripts --no-progress --non-interactive
56     patchShebangs node_modules/
58     runHook postConfigure
59   '';
61   # Only affects unused scripts in $out/share/element/electron/scripts. Also
62   # breaks because there are some `node`-scripts with a `npx`-shebang and
63   # this shouldn't be in the closure just for unused scripts.
64   dontPatchShebangs = true;
66   buildPhase = ''
67     runHook preBuild
69     yarn --offline run build:ts
70     yarn --offline run i18n
71     yarn --offline run build:res
73     rm -rf node_modules/matrix-seshat node_modules/keytar
74     ${lib.optionalString useKeytar "ln -s ${keytar} node_modules/keytar"}
75     ln -s $seshat node_modules/matrix-seshat
77     runHook postBuild
78   '';
80   installPhase =
81   ''
82     runHook preInstall
84     # resources
85     mkdir -p "$out/share/element"
86     ln -s '${element-web}' "$out/share/element/webapp"
87     cp -r '.' "$out/share/element/electron"
88     cp -r './res/img' "$out/share/element"
89     rm -rf "$out/share/element/electron/node_modules"
90     cp -r './node_modules' "$out/share/element/electron"
91     cp $out/share/element/electron/lib/i18n/strings/en_EN.json $out/share/element/electron/lib/i18n/strings/en-us.json
92     ln -s $out/share/element/electron/lib/i18n/strings/en{-us,}.json
94     # icons
95     for icon in $out/share/element/electron/build/icons/*.png; do
96       mkdir -p "$out/share/icons/hicolor/$(basename $icon .png)/apps"
97       ln -s "$icon" "$out/share/icons/hicolor/$(basename $icon .png)/apps/element.png"
98     done
100     # desktop item
101     mkdir -p "$out/share"
102     ln -s "${finalAttrs.desktopItem}/share/applications" "$out/share/applications"
104     # executable wrapper
105     # LD_PRELOAD workaround for sqlcipher not found: https://github.com/matrix-org/seshat/issues/102
106     makeWrapper '${electron}/bin/electron' "$out/bin/${executableName}" \
107       --set LD_PRELOAD ${sqlcipher}/lib/libsqlcipher.so \
108       --add-flags "$out/share/element/electron" \
109       --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}"
111     runHook postInstall
112   '';
114   # The desktop item properties should be kept in sync with data from upstream:
115   # https://github.com/vector-im/element-desktop/blob/develop/package.json
116   desktopItem = makeDesktopItem {
117     name = "element-desktop";
118     exec = "${executableName} %u";
119     icon = "element";
120     desktopName = "Element";
121     genericName = "Matrix Client";
122     comment = finalAttrs.meta.description;
123     categories = [ "Network" "InstantMessaging" "Chat" ];
124     startupWMClass = "Element";
125     mimeTypes = [ "x-scheme-handler/element" ];
126   };
128   postFixup = lib.optionalString stdenv.isDarwin ''
129     cp build/icon.icns $out/Applications/Element.app/Contents/Resources/element.icns
130   '';
132   passthru = {
133     updateScript = ./update.sh;
135     # TL;DR: keytar is optional while seshat isn't.
136     #
137     # This prevents building keytar when `useKeytar` is set to `false`, because
138     # if libsecret is unavailable (e.g. set to `null` or fails to build), then
139     # this package wouldn't even considered for building because
140     # "one of the dependencies failed to build",
141     # although the dependency wouldn't even be used.
142     #
143     # It needs to be `passthru` anyways because other packages do depend on it.
144     inherit keytar;
145   };
147   meta = with lib; {
148     description = "A feature-rich client for Matrix.org";
149     homepage = "https://element.io/";
150     changelog = "https://github.com/vector-im/element-desktop/blob/v${finalAttrs.version}/CHANGELOG.md";
151     license = licenses.asl20;
152     maintainers = teams.matrix.members;
153     inherit (electron.meta) platforms;
154     mainProgram = "element-desktop";
155   };