Matrix: Difference between revisions

Klinger (talk | contribs)
mNo edit summary
m fix config file url
 
(10 intermediate revisions by 3 users not shown)
Line 28: Line 28:
A [https://search.nixos.org/packages?query=purple-matrix Pidgin / libpurple plugin] is also available.
A [https://search.nixos.org/packages?query=purple-matrix Pidgin / libpurple plugin] is also available.


==== Element ====
=== Web clients ===


The [https://github.com/vector-im/element-web/blob/develop/config.sample.json config.json] file used by Element can be configured as such:
==== element-web ====
There is also a web version of [https://search.nixos.org/packages?query=element-web Element] which can be served using a web server. See [https://nixos.org/nixos/manual/index.html#module-services-matrix-element-web the NixOS manual entry].<syntaxhighlight lang="nixos">
{
  services.nginx.enable = true;


<syntaxhighlight lang="nix">
  # See https://nixos.org/manual/nixos/stable/index.html#module-services-matrix-element-web
nixpkgs.config.element-web.conf = {
  services.nginx.virtualHosts."localhost" = {
  show_labs_settings = true;
    listen = [{
   default_theme = "dark";
      addr = "[::1]";
};
      port = yourPort;
    }];
    root = pkgs.element-web.override {
      # See https://github.com/element-hq/element-web/blob/develop/config.sample.json
      conf = {
        default_theme = "dark";
      };
    };
  };
}
</syntaxhighlight>Alternatively, you can write a script to start the web client on demand.<syntaxhighlight lang="nix">
let
  # port = yourPort;
  web-dir = pkgs.element-web.override {
    conf = {
      default_theme = "dark";
      show_labs_settings = true;
    };
   };
  element-web = pkgs.writeScriptBin "element-web" ''
    #!${pkgs.bash}/bin/bash
    set -e
    ${pkgs.python3}/bin/python3 -m http.server ${port} -b ::1 -d ${web-dir}
  '';
in
{
  home.sessionPath = [ "${element-web}/bin" ];
}
</syntaxhighlight>
</syntaxhighlight>
=== Web clients ===
There is also a web version of [https://search.nixos.org/packages?query=element-web Element] which can be served using a web server. See [https://nixos.org/nixos/manual/index.html#module-services-matrix-element-web the NixOS manual entry].


== Servers ==
== Servers ==


=== Homeservers ===
=== Homeservers ===
==== Conduit ====
<syntaxhighlight lang="nixos">
{
  # See https://search.nixos.org/options?channel=unstable&query=services.matrix-conduit.
  # and https://docs.conduit.rs/configuration.html
  services.matrix-conduit = {
    enable = true;
    settings.global = {
      # allow_registration = true;
      # server_name = yourDomainName;
      # port = yourPort;
      address = "::1";
      database_backend = "rocksdb";
      # See https://www.metered.ca/tools/openrelay
      turn_uris = [
        "turn:staticauth.openrelay.metered.ca:80?transport=udp"
        "turn:staticauth.openrelay.metered.ca:80?transport=tcp"
      ];
      turn_secret = "openrelayprojectsecret";
    };
  };
}
</syntaxhighlight>


==== Synapse ====
==== Synapse ====


Currently, only the reference Matrix homeserver [https://matrix.org/docs/projects/server/synapse Synapse] is  [https://search.nixos.org/packages?query=matrix-synapse packaged] for NixOS. It has an associated module exposing the [https://search.nixos.org/options?query=services.matrix-synapse services.matrix-synapse.* options]. See [https://nixos.org/nixos/manual/index.html#module-services-matrix-synapse the NixOS manual entry] for a complete configuration example.
[https://element-hq.github.io/synapse/latest/welcome_and_overview.html Synapse] has an associated module exposing the [https://search.nixos.org/options?query=services.matrix-synapse services.matrix-synapse.* options]. See [https://nixos.org/nixos/manual/index.html#module-services-matrix-synapse the NixOS manual entry] for a complete configuration example.


===== Coturn with Synapse =====
===== Coturn with Synapse =====
For WebRTC calls to work when both callers are behind a NAT, you need to provide a turn server for clients to use. Here is an example configuration, inspired from [https://github.com/spantaleev/matrix-docker-ansible-deploy/blob/master/roles/matrix-coturn/templates/turnserver.conf.j2 this configuration file].
For WebRTC calls to work when both callers are behind a NAT, you need to provide a turn server for clients to use. Here is an example configuration, inspired from [https://github.com/spantaleev/matrix-docker-ansible-deploy/blob/master/roles/custom/matrix-coturn/templates/turnserver.conf.j2 this configuration file].


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 100: Line 150:
   networking.firewall = {
   networking.firewall = {
     interfaces.enp2s0 = let
     interfaces.enp2s0 = let
       range = with config.services.coturn; [ {
       range = with config.services.coturn; lib.singleton {
      from = min-port;
        from = min-port;
      to = max-port;
        to = max-port;
    } ];
      };
     in
     in
     {
     {
Line 119: Line 169:
   };
   };
   # configure synapse to point users to coturn
   # configure synapse to point users to coturn
   services.matrix-synapse = with config.services.coturn; {
   services.matrix-synapse.settings = with config.services.coturn; {
     turn_uris = ["turn:${realm}:3478?transport=udp" "turn:${realm}:3478?transport=tcp"];
     turn_uris = ["turn:${realm}:3478?transport=udp" "turn:${realm}:3478?transport=tcp"];
     turn_shared_secret = static-auth-secret;
     turn_shared_secret = static-auth-secret;