~sumner/nixos-configuration

ref: 7e558d0d52b4201b2e0b7de2eb1a2d75fab02a2e nixos-configuration/modules/services/matrix/synapse/shared-config.nix -rw-r--r-- 3.4 KiB
7e558d0dSumner Evans matrix-synapse: email config for nevarro 2 months ago
                                                                                
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# This is organized to match the sections in
# https://github.com/matrix-org/synapse/blob/develop/docs/sample_config.yaml
{ config, lib, pkgs }: with lib;
let
  cfg = config.services.matrix-synapse-custom;
  yamlFormat = pkgs.formats.yaml { };

  logConfig = {
    version = 1;
    formatters.journal_fmt.format = "%(name)s: [%(request)s] %(message)s";
    filters.context = {
      "()" = "synapse.util.logcontext.LoggingContextFilter";
      request = "";
    };
    handlers.journal = {
      class = "systemd.journal.JournalHandler";
      formatter = "journal_fmt";
      filters = [ "context" ];
      SYSLOG_IDENTIFIER = "synapse";
    };
    root = { level = "INFO"; handlers = [ "journal" ]; };
    disable_existing_loggers = false;
  };
in
{
  # Server
  server_name = config.networking.domain;
  pid_file = "/run/matrix-synapse.pid";
  default_room_version = "9";
  public_baseurl = "https://matrix.${config.networking.domain}";
  listeners = [
    # CS API and Federation
    {
      type = "http";
      port = 8008;
      bind_address = "0.0.0.0";
      tls = false;
      x_forwarded = true;
      resources = [
        { names = [ "federation" "client" ]; compress = false; }
      ];
    }

    # Metrics
    {
      port = 9009;
      bind_address = "0.0.0.0";
      tls = false;
      type = "metrics";
    }

    # Replication
    {
      type = "http";
      port = 9093;
      bind_address = "127.0.0.1";
      resources = [{ names = [ "replication" ]; }];
    }
  ];

  # Caching
  event_cache_size = "25K";
  caches.global_factor = 1.0;

  # Database
  database = {
    name = "psycopg2";
    args = { user = "matrix-synapse"; database = "matrix-synapse"; };
  };

  # Logging
  log_config = yamlFormat.generate "matrix-synapse-log-config.yaml" logConfig;

  # Media store
  enable_media_repo = false;
  media_store_path = "${cfg.dataDir}/media";
  max_upload_size = "250M";
  url_preview_enabled = true;
  url_preview_ip_range_blacklist = [
    "127.0.0.0/8"
    "10.0.0.0/8"
    "172.16.0.0/12"
    "192.168.0.0/16"
    "100.64.0.0/10"
    "169.254.0.0/16"
    "::1/128"
    "fe80::/64"
    "fc00::/7"
  ];

  url_preview_url_blacklist = [
    # blacklist any URL with a username in its URI
    { username = "*"; }

    # Don't try previews for Linear.
    { netloc = "linear.app"; }
  ];

  # TURN
  # Configure coturn to point at the matrix.org servers.
  # TODO actually figure this out eventually
  turn_uris = [
    "turn:turn.matrix.org?transport=udp"
    "turn:turn.matrix.org?transport=tcp"
  ];
  turn_shared_secret = "n0t4ctuAllymatr1Xd0TorgSshar3d5ecret4obvIousreAsons";
  turn_user_lifetime = "1h";

  # Registration
  enable_registration = false;
  registration_shared_secret = removeSuffix "\n" (readFile cfg.registrationSharedSecretFile);

  # Metrics
  enable_metrics = true;
  report_stats = true;

  # API Configuration
  app_service_config_files = cfg.appServiceConfigFiles;

  # Signing Keys
  signing_key_path = "${cfg.dataDir}/homeserver.signing.key";
  trusted_key_servers = [
    { server_name = "matrix.org"; }
  ];
  suppress_key_server_warning = true;

  # Email
  email = cfg.emailCfg;

  # Workers
  send_federation = false;
  federation_sender_instances = [ "federation_sender1" ];
  instance_map = {
    event_persister1 = {
      host = "localhost";
      port = 9091;
    };
  };

  stream_writers = {
    events = "event_persister1";
  };

  redis = {
    enabled = true;
  };
}