about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/networking/instant-messengers/schildichat/schildichat-desktop.nix
blob: e2b4cafe99361f720b2b61728dc0f889036aa704 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
{ lib
, element-desktop # for seshat and keytar
, schildichat-web
, stdenv
, fetchFromGitHub
, makeWrapper
, makeDesktopItem
, copyDesktopItems
, fetchYarnDeps
, yarn
, nodejs
, fixup_yarn_lock
, electron
, Security
, AppKit
, CoreServices
}:

let
  pinData = lib.importJSON ./pin.json;
  executableName = "schildichat-desktop";
  electron_exec = if stdenv.isDarwin then "${electron}/Applications/Electron.app/Contents/MacOS/Electron" else "${electron}/bin/electron";
in
stdenv.mkDerivation rec {
  pname = "schildichat-desktop";
  inherit (pinData) version;

  src = fetchFromGitHub {
    owner = "SchildiChat";
    repo = "schildichat-desktop";
    inherit (pinData) rev;
    sha256 = pinData.srcHash;
    fetchSubmodules = true;
  };

  offlineCache = fetchYarnDeps {
    yarnLock = src + "/element-desktop/yarn.lock";
    sha256 = pinData.desktopYarnHash;
  };

  nativeBuildInputs = [ yarn fixup_yarn_lock nodejs makeWrapper copyDesktopItems ];
  inherit (element-desktop) seshat keytar;

  configurePhase = ''
    runHook preConfigure

    export HOME=$(mktemp -d)
    pushd element-desktop
    yarn config --offline set yarn-offline-mirror $offlineCache
    fixup_yarn_lock yarn.lock
    yarn install --offline --frozen-lockfile --ignore-platform --ignore-scripts --no-progress --non-interactive
    rm -rf node_modules/matrix-seshat node_modules/keytar
    ln -s $keytar node_modules/keytar
    ln -s $seshat node_modules/matrix-seshat
    patchShebangs node_modules/
    popd

    runHook postConfigure
  '';

  buildPhase = ''
    runHook preBuild

    pushd element-desktop
    npx tsc
    yarn run i18n
    node ./scripts/copy-res.js
    popd

    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall

    # resources
    mkdir -p "$out/share/element"
    ln -s '${schildichat-web}' "$out/share/element/webapp"
    mv element-desktop "$out/share/element/electron"
    cp -r "$out/share/element/electron/res/img" "$out/share/element"
    cp $out/share/element/electron/lib/i18n/strings/en_EN.json $out/share/element/electron/lib/i18n/strings/en-us.json
    ln -s $out/share/element/electron/lib/i18n/strings/en{-us,}.json

    # icons
    for icon in $out/share/element/electron/build/icons/*.png; do
      mkdir -p "$out/share/icons/hicolor/$(basename $icon .png)/apps"
      ln -s "$icon" "$out/share/icons/hicolor/$(basename $icon .png)/apps/schildichat.png"
    done

    # executable wrapper
    makeWrapper '${electron_exec}' "$out/bin/${executableName}" \
      --add-flags "$out/share/element/electron" \
      --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--enable-features=UseOzonePlatform --ozone-platform=wayland}}"

    runHook postInstall
  '';

  # Do not attempt generating a tarball for element-web again.
  # note: `doDist = false;` does not work.
  distPhase = ";";

  # The desktop item properties should be kept in sync with data from upstream:
  # https://github.com/schildichat/element-desktop/blob/sc/package.json
  desktopItems = [
    (makeDesktopItem {
      name = "schildichat-desktop";
      exec = "${executableName} %u";
      icon = "schildichat";
      desktopName = "SchildiChat";
      genericName = "Matrix Client";
      comment = meta.description;
      categories = [ "Network" "InstantMessaging" "Chat" ];
      startupWMClass = "schildichat";
      mimeTypes = [ "x-scheme-handler/element" ];
    })
  ];

  passthru.updateScript = ./update.sh;

  meta = {
    description = "Matrix client / Element Desktop fork";
    homepage = "https://schildi.chat/";
    changelog = "https://github.com/SchildiChat/schildichat-desktop/releases";
    maintainers = lib.teams.matrix.members ++ [ lib.maintainers.kloenk ];
    license = lib.licenses.asl20;
    platforms = lib.platforms.all;
  };
}