blob: 2feff8c379aa2aba6d6db25603001764727b43fc (
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
{ config, pkgs, lib, ... }:
let
#federationSenders = lib.range 0 31;
#federationReceivers = lib.range 10000 10000;
#initialSyncWorkers = lib.range 10100 10100;
#syncWorkers = lib.range 10150 10150;
#streamWriters = lib.range 10200 10200;
in
{
# Worker plumbing examples: https://github.com/element-hq/synapse/blob/master/docker/configure_workers_and_start.py
# Documentation: https://github.com/element-hq/synapse/blob/develop/docs/workers.md
imports = [
./workers/module.nix
];
services.matrix-synapse = {
enable = true;
withJemalloc = true;
federationSenders = 2;
pushers = 2;
enableStreamWriters = false;
enableAppserviceWorker = true;
#eventStreamWriters = 8;
# https://matrix-org.github.io/synapse/latest/usage/configuration/config_documentation.html
settings = {
server_name = "rory.gay";
enable_registration = true;
registration_requires_token = true;
require_membership_for_aliases = false;
redaction_retention_period = null;
user_ips_max_age = null;
allow_device_name_lookup_over_federation = true;
federation = {
client_timeout = "60s";
max_short_retries = 12;
max_short_retry_delay = "5s";
max_long_retries = 5;
max_long_retry_delay = "30s";
};
# Alicia - figure this out later...
#registration_shared_secret = builtins.exec ["cat" "/dev/urandom" "|" "tr" "-dc" "a-zA-Z0-9" "|" "fold" "-w" "256" "|" "head" "-n" "1"];
registration_shared_secret_path = "/var/lib/matrix-synapse/registration_shared_secret.txt";
listeners = [
{
port = 8008;
bind_addresses = [ "192.168.1.2" "127.0.0.1" ];
type = "http";
tls = false;
x_forwarded = true;
resources = [ {
names = [ "client" "federation" ];
compress = false;
} ];
}
{
type = "http";
path = "/run/matrix-synapse/replication-listener.sock";
resources = [ {
names = [ "replication" ];
compress = false;
} ];
}
];
dynamic_thumbnails = true;
presence = {
enable = true;
update_interval = 60;
};
url_preview_enabled = true;
database = (import ./db.nix { workerName = "main"; dbGroup = "medium"; });
#database = {
# name = "psycopg2";
# args = {
# user = "matrix-synapse-rory-gay";
# #passwordFile = "/run/secrets/matrix-synapse-password";
# password = "somepassword";
# database = "matrix-synapse-rory-gay";
# #host = "127.0.0.1";
# host = "/run/postgresql";
# application_name = "matrix-synapse (rory.gay)";
# cp_min = 5;
# cp_max = 10;
# #cp_reconnect_interval = "True";
# };
#};
app_service_config_files = [
#"/etc/matrix-synapse/appservice-registration.yaml"
"/var/lib/matrix-synapse/modas-registration.yaml"
];
max_image_pixels = "100M";
ui_auth = {
session_timeout = "1m";
};
login_via_existing_session = {
enabled = true;
require_ui_auth = true;
token_timeout = "1y";
};
report_stats = false;
user_directory = {
enabled = true;
search_all_users = true;
prefer_local_users = true;
};
experimental_features = {
# These apparently arent valid...
#"org.matrix.msc3026.busy_presence" = true;
#"fi.mau.msc2815" = true;
#"org.matrix.msc3881" = true;
#"org.matrix.msc3874" = true;
#"org.matrix.msc3912" = true;
# These should be, looking at synapse's experimental.py
"msc2815_enabled" = true; # Redacted event content
"msc3026_enabled" = true; # Busy presence
"msc3266_enabled" = true; # Room summary API
"msc3916_authenticated_media_enabled" = true; # Authenticated media
};
redis = {
enabled = true;
path = "/run/redis-matrix-synapse/redis.sock";
};
instance_map = {
main = { # replication listener
#host = "127.0.0.1";
#port = 8009;
path = "/run/matrix-synapse/replication-listener.sock";
};
} ;
### // builtins.listToAttrs (map (port: {
### name = "federation_sender-${toString port}";
### value = {
### path = "/run/matrix-synapse/federation_sender-${toString port}.sock";
### };
### }) federationSenders);
#} // builtins.listToAttrs (map (port: {
# name = "federation_receiver-${toString port}";
# value = {
# path = "/run/matrix-synapse/federation_receiver-${toString port}.sock";
# };
#}) federationReceivers);
# by type:
#federation_sender_instances = map (port: "federation_sender-${toString port}") federationSenders;
}
// import ./ratelimits.nix
// import ./caches.nix;
## TODO: INVESTIGATE
# worker_listeners:
# - type: metrics
# bind_address: ''
# port: 9101
#workers =
#builtins.listToAttrs (map (port: {
# name = "federation_receiver-${toString port}";
# value = {
# worker_app = "synapse.app.generic_worker";
# worker_listeners = [
# {
# port = port;
# type = "http";
# resources = [ {
# names = [ "federation" ];
# compress = false;
# } ];
# }
# ];
# };
#}) federationReceivers)
### builtins.listToAttrs (map (port: {
### name = "federation_sender-${toString port}";
### value = {
### worker_app = "synapse.app.generic_worker";
### worker_listeners = [ ];
### database = (import ./db.nix { workerName = "federation sender ${toString port}"; dbGroup = "small"; });
### };
### }) federationSenders);
};
systemd.services.matrix-synapse-reg-token = {
description = "Random registration token for Synapse.";
before = ["matrix-synapse.service"]; # So the registration can be used by Synapse
wantedBy = ["multi-user.target"];
after = ["network.target"];
script = ''
if [ ! -f "registration_shared_secret.txt" ]
then
cat /dev/urandom | tr -dc a-zA-Z0-9 | fold -w 256 | head -n 1 > registration_shared_secret.txt
else
echo Not generating key, key exists;
fi'';
serviceConfig = {
User = "matrix-synapse";
Group = "matrix-synapse";
WorkingDirectory = "/var/lib/matrix-synapse";
};
};
services.redis = {
package = pkgs.keydb;
servers.matrix-synapse = {
enable = true;
user = "matrix-synapse";
};
};
systemd.tmpfiles.rules = [
"D /run/redis-matrix-synapse 0755 matrix-synapse matrix-synapse"
];
}
|