about summary refs log tree commit diff
path: root/pkgs/applications/networking/instant-messengers/element/element-web.nix
blob: 6af1c2ec738ad9e4bcb098774ee5de17be329139 (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
{ lib
, stdenv
, runCommand
, fetchFromGitHub
, fetchYarnDeps
, writeText
, jq
, yarn
, fixup_yarn_lock
, nodejs
, jitsi-meet
, conf ? { }
}:

let
  pinData = lib.importJSON ./pin.json;
  noPhoningHome = {
    disable_guests = true; # disable automatic guest account registration at matrix.org
  };

  unwrapped = stdenv.mkDerivation rec {
    pname = "element-web";
    inherit (pinData) version;

    src = fetchFromGitHub {
      owner = "vector-im";
      repo = pname;
      rev = "v${version}";
      sha256 = pinData.webSrcHash;
    };

    offlineCache = fetchYarnDeps {
      yarnLock = src + "/yarn.lock";
      sha256 = pinData.webYarnHash;
    };

    nativeBuildInputs = [ yarn fixup_yarn_lock jq nodejs ];

    configurePhase = ''
      runHook preConfigure

      export HOME=$PWD/tmp
      # with the update of openssl3, some key ciphers are not supported anymore
      # this flag will allow those codecs again as a workaround
      # see https://medium.com/the-node-js-collection/node-js-17-is-here-8dba1e14e382#5f07
      # and https://github.com/vector-im/element-web/issues/21043
      export NODE_OPTIONS=--openssl-legacy-provider
      mkdir -p $HOME

      fixup_yarn_lock yarn.lock
      yarn config --offline set yarn-offline-mirror $offlineCache
      yarn install --offline --frozen-lockfile --ignore-platform --ignore-scripts --no-progress --non-interactive
      patchShebangs node_modules

      runHook postConfigure
    '';

    buildPhase = ''
      runHook preBuild

      export VERSION=${version}
      yarn build:res --offline
      yarn build:module_system --offline
      yarn build:bundle --offline

      runHook postBuild
    '';

    installPhase = ''
      runHook preInstall

      cp -R webapp $out
      cp ${jitsi-meet}/libs/external_api.min.js $out/jitsi_external_api.min.js
      echo "${version}" > "$out/version"
      jq -s '.[0] * $conf' "config.sample.json" --argjson "conf" '${builtins.toJSON noPhoningHome}' > "$out/config.json"

      runHook postInstall
    '';

    meta = {
      description = "A glossy Matrix collaboration client for the web";
      homepage = "https://element.io/";
      changelog = "https://github.com/vector-im/element-web/blob/v${version}/CHANGELOG.md";
      maintainers = lib.teams.matrix.members;
      license = lib.licenses.asl20;
      platforms = lib.platforms.all;
    };
  };
in
if (conf == { }) then unwrapped else
stdenv.mkDerivation rec {
  pname = "${unwrapped.pname}-wrapped";
  inherit (unwrapped) version meta;

  dontUnpack = true;

  nativeBuildInputs = [ jq ];

  installPhase = ''
    runHook preInstall

    mkdir -p $out
    ln -s ${unwrapped}/* $out
    rm $out/config.json
    jq -s '.[0] * $conf' "${unwrapped}/config.json" --argjson "conf" '${builtins.toJSON conf}' > "$out/config.json"

    runHook postInstall
  '';
}