about summary refs log tree commit diff
path: root/overlays/sliding-sync-module.nix
blob: 8117e2b3371f8a9db2c6f651fa260c4547f10da8 (plain)
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
{ config, lib, pkgs, ... }:
let
  cfg = config.services.sliding-sync;
in
{
  # TODO: add default values
  options.services.sliding-sync = {
    enable = lib.mkEnableOption (lib.mdDoc "matrix.org sliding-sync");
    server = lib.mkOption {
      type = lib.types.str;
      # default = "https://matrix-client.matrix.org" # TODO: required?
      description = lib.mdDoc ''
        The destination homeserver to talk to (CS API HTTPS URL)
      '';
    };
    db = lib.mkOption {
      type = lib.types.str;
      description = lib.mdDoc ''
        The postgres connection string: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
      '';
    };
    bindAddr = lib.mkOption {
      type = lib.types.str;
      default = "0.0.0.0:8008";
      description = lib.mdDoc ''
        The interface and port to listen on.
      '';
    };
    secret = lib.mkOption {
      type = lib.types.str;
      description = lib.mdDoc ''
        A secret to use to encrypt access tokens.
        Must remain the same for the lifetime of the database.
      '';
    };
    pprof = lib.mkOption {
      type = lib.types.nullOr lib.types.str;
      default = null;
      description = lib.mdDoc ''
        The bind addr for pprof debugging e.g ':6060'.
        If not set, does not listen.
      '';
    };
    prom = lib.mkOption {
      type = lib.types.nullOr lib.types.str;
      default = null;
      description = lib.mdDoc ''
        The bind addr for Prometheus metrics,
        which will be accessible at /metrics at this address.
      '';
    };
    jaegerUrl = lib.mkOption {
      type = lib.types.nullOr lib.types.str;
      default = null;
      description = lib.mdDoc ''
        The Jaeger URL to send spans to e.g http://localhost:14268/api/traces
        If unset does not send OTLP traces.
      '';
    };
    after = lib.mkOption {
      type = lib.types.listOf lib.types.str;
      default = null;
      description = lib.mdDoc ''
        The service that should start before the sliding-sync proxy.
      '';
    };
  };

  config = lib.mkIf cfg.enable {
    systemd.services.sliding-sync = {
      description = "MSC3575 Matrix Sliding Sync Proxy";
      after = [
        "network.target"
      ] ++ cfg.after;
      wantedBy = [ "multi-user.target" ];
      serviceConfig = {
        Type = "simple";
        DynamicUser = true;
        ExecStart =
          "${pkgs.matrix-sliding-sync}/bin/syncv3";
        Restart = "on-failure";
      };
      environment = {
        SYNCV3_SERVER = cfg.server;
        SYNCV3_DB = cfg.db;
        SYNCV3_SECRET = cfg.secret;
        SYNCV3_BINDADDR = cfg.bindAddr;
        SYNCV3_PPROF = cfg.pprof;
        SYNCV3_PROM = cfg.prom;
        SYNCV3_JAEGER_URL = cfg.jaegerUrl;
      };
    };
  };
}