18 , desktopToDarwinBundle
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 {
34 repo = "element-desktop";
35 rev = "v${finalAttrs.version}";
36 hash = desktopSrcHash;
39 offlineCache = fetchYarnDeps {
40 yarnLock = finalAttrs.src + "/yarn.lock";
41 sha256 = desktopYarnHash;
44 nativeBuildInputs = [ yarn fixup-yarn-lock nodejs makeWrapper jq ]
45 ++ lib.optionals stdenv.isDarwin [ desktopToDarwinBundle ];
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/
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;
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
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
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"
101 mkdir -p "$out/share"
102 ln -s "${finalAttrs.desktopItem}/share/applications" "$out/share/applications"
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}}"
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";
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" ];
128 postFixup = lib.optionalString stdenv.isDarwin ''
129 cp build/icon.icns $out/Applications/Element.app/Contents/Resources/element.icns
133 updateScript = ./update.sh;
135 # TL;DR: keytar is optional while seshat isn't.
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.
143 # It needs to be `passthru` anyways because other packages do depend on it.
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";