git.iko.soy/typeable/nixpkgs
on master help sign in
matrix-synapse: 0.14 -> 0.16
commit26da79230b30653eefdb574b05ad6de65e0efdd5 authorBenjamin Saunders <ben.e.saunders@gmail.com> dateTue 14 Jun 2016, 17:50 (10 years ago) parent091a911
2 files changed+297−37
nixos/modules/services/misc/matrix-synapse.nix+292−32 pkgs/servers/matrix-synapse/default.nix+5−5
nixos/modules/services/misc/matrix-synapse.nix+292−32
@@ -5,17 +5,31 @@ with lib;
55let
66 cfg = config.services.matrix-synapse;
77 logConfigFile = pkgs.writeText "log_config.yaml" cfg.logConfig;
8+ mkResource = r: ''{names: ${builtins.toJSON r.names}, compress: ${if r.compress then "true" else "false"}}'';
9+ mkListener = l: ''{port: ${toString l.port}, bind_address: "${l.bind_address}", type: ${l.type}, tls: ${if l.tls then "true" else "false"}, x_forwarded: ${if l.x_forwarded then "true" else "false"}, resources: [${concatStringsSep "," (map mkResource l.resources)}]}'';
810 configFile = pkgs.writeText "homeserver.yaml" ''
911tls_certificate_path: "${cfg.tls_certificate_path}"
12+${optionalString (cfg.tls_private_key_path != null) ''
1013tls_private_key_path: "${cfg.tls_private_key_path}"
14+''}
1115tls_dh_params_path: "${cfg.tls_dh_params_path}"
1216no_tls: ${if cfg.no_tls then "true" else "false"}
17+${optionalString (cfg.bind_port != null) ''
1318bind_port: ${toString cfg.bind_port}
19+''}
20+${optionalString (cfg.unsecure_port != null) ''
1421unsecure_port: ${toString cfg.unsecure_port}
22+''}
23+${optionalString (cfg.bind_host != null) ''
1524bind_host: "${cfg.bind_host}"
25+''}
1626server_name: "${cfg.server_name}"
1727pid_file: "/var/run/matrix-synapse.pid"
1828web_client: ${if cfg.web_client then "true" else "false"}
29+${optionalString (cfg.public_baseurl != null) ''
30+public_baseurl: "${cfg.public_baseurl}"
31+''}
32+listeners: [${concatStringsSep "," (map mkListener cfg.listeners)}]
1933database: {
2034 name: "${cfg.database_type}",
2135 args: {
@@ -24,21 +38,41 @@ database: {
2438 )}
2539 }
2640}
41+event_cache_size: "${cfg.event_cache_size}"
42+verbose: ${cfg.verbose}
2743log_file: "/var/log/matrix-synapse/homeserver.log"
2844log_config: "${logConfigFile}"
45+rc_messages_per_second: ${cfg.rc_messages_per_second}
46+rc_message_burst_count: ${cfg.rc_message_burst_count}
47+federation_rc_window_size: ${cfg.federation_rc_window_size}
48+federation_rc_sleep_limit: ${cfg.federation_rc_sleep_limit}
49+federation_rc_sleep_delay: ${cfg.federation_rc_sleep_delay}
50+federation_rc_reject_limit: ${cfg.federation_rc_reject_limit}
51+federation_rc_concurrent: ${cfg.federation_rc_concurrent}
2952media_store_path: "/var/lib/matrix-synapse/media"
53+uploads_path: "/var/lib/matrix-synapse/uploads"
54+max_upload_size: "${cfg.max_upload_size}"
55+max_image_pixels: "${cfg.max_image_pixels}"
56+dynamic_thumbnails: ${if cfg.dynamic_thumbnails then "true" else "false"}
57+url_preview_enabled: False
3058recaptcha_private_key: "${cfg.recaptcha_private_key}"
3159recaptcha_public_key: "${cfg.recaptcha_public_key}"
3260enable_registration_captcha: ${if cfg.enable_registration_captcha then "true" else "false"}
33−turn_uris: ${if (length cfg.turn_uris) == 0 then "[]" else ("\n" + (concatStringsSep "\n" (map (s: "- " + s) cfg.turn_uris)))}
61+turn_uris: ${builtins.toJSON cfg.turn_uris}
3462turn_shared_secret: "${cfg.turn_shared_secret}"
3563enable_registration: ${if cfg.enable_registration then "true" else "false"}
36−${optionalString (cfg.registration_shared_secret != "") ''
64+${optionalString (cfg.registration_shared_secret != null) ''
3765registration_shared_secret: "${cfg.registration_shared_secret}"
3866''}
67+recaptcha_siteverify_api: "https://www.google.com/recaptcha/api/siteverify"
68+turn_user_lifetime: "${cfg.turn_user_lifetime}"
69+user_creation_max_duration: ${cfg.user_creation_max_duration}
70+bcrypt_rounds: ${cfg.bcrypt_rounds}
71+allow_guest_access: {if cfg.allow_guest_access then "true" else "false"}
3972enable_metrics: ${if cfg.enable_metrics then "true" else "false"}
4073report_stats: ${if cfg.report_stats then "true" else "false"}
4174signing_key_path: "/var/lib/matrix-synapse/homeserver.signing.key"
75+key_refresh_interval: "${cfg.key_refresh_interval}"
4276perspectives:
4377 servers: {
4478 ${concatStringsSep "},\n" (mapAttrsToList (n: v: ''
@@ -52,6 +86,8 @@ perspectives:
5286 '') cfg.servers)}
5387 }
5488 }
89+app_service_config_files: ${builtins.toJSON cfg.app_service_config_files}
90+
5591${cfg.extraConfig}
5692'';
5793in {
@@ -73,53 +109,65 @@ in {
73109 Don't bind to the https port
74110 '';
75111 };
76− tls_certificate_path = mkOption {
77− type = types.path;
78− default = "/var/lib/matrix-synapse/homeserver.tls.crt";
112+ bind_port = mkOption {
113+ type = types.nullOr types.int;
114+ default = null;
115+ example = 8448;
79116 description = ''
80− PEM encoded X509 certificate for TLS
117+ DEPRECATED: Use listeners instead.
118+ The port to listen for HTTPS requests on.
119+ For when matrix traffic is sent directly to synapse.
81120 '';
82121 };
83− tls_private_key_path = mkOption {
84− type = types.path;
85− default = "/var/lib/matrix-synapse/homeserver.tls.key";
122+ unsecure_port = mkOption {
123+ type = types.nullOr types.int;
124+ default = null;
125+ example = 8008;
86126 description = ''
87− PEM encoded private key for TLS
127+ DEPRECATED: Use listeners instead.
128+ The port to listen for HTTP requests on.
129+ For when matrix traffic passes through loadbalancer that unwraps TLS.
88130 '';
89131 };
90− tls_dh_params_path = mkOption {
91− type = types.path;
92− default = "/var/lib/matrix-synapse/homeserver.tls.dh";
132+ bind_host = mkOption {
133+ type = types.nullOr types.str;
134+ default = null;
93135 description = ''
94− PEM dh parameters for ephemeral keys
136+ DEPRECATED: Use listeners instead.
137+ Local interface to listen on.
138+ The empty string will cause synapse to listen on all interfaces.
95139 '';
96140 };
97− bind_port = mkOption {
98− type = types.int;
99− default = 8448;
141+ tls_certificate_path = mkOption {
142+ type = types.str;
143+ default = "/var/lib/matrix-synapse/homeserver.tls.crt";
100144 description = ''
101− The port to listen for HTTPS requests on.
102− For when matrix traffic is sent directly to synapse.
145+ PEM encoded X509 certificate for TLS.
146+ You can replace the self-signed certificate that synapse
147+ autogenerates on launch with your own SSL certificate + key pair
148+ if you like. Any required intermediary certificates can be
149+ appended after the primary certificate in hierarchical order.
103150 '';
104151 };
105− unsecure_port = mkOption {
106− type = types.int;
107− default = 8008;
152+ tls_private_key_path = mkOption {
153+ type = types.nullOr types.str;
154+ default = "/var/lib/matrix-synapse/homeserver.tls.key";
155+ example = null;
108156 description = ''
109− The port to listen for HTTP requests on.
110− For when matrix traffic passes through loadbalancer that unwraps TLS.
157+ PEM encoded private key for TLS. Specify null if synapse is not
158+ speaking TLS directly.
111159 '';
112160 };
113− bind_host = mkOption {
161+ tls_dh_params_path = mkOption {
114162 type = types.str;
115− default = "";
163+ default = "/var/lib/matrix-synapse/homeserver.tls.dh";
116164 description = ''
117− Local interface to listen on.
118− The empty string will cause synapse to listen on all interfaces.
165+ PEM dh parameters for ephemeral keys
119166 '';
120167 };
121168 server_name = mkOption {
122169 type = types.str;
170+ example = "example.com";
123171 description = ''
124172 The domain name of the server, with optional explicit port.
125173 This is used by remote servers to connect to this server,
@@ -134,6 +182,145 @@ in {
134182 Whether to serve a web client from the HTTP/HTTPS root resource.
135183 '';
136184 };
185+ public_baseurl = mkOption {
186+ type = types.nullOr types.str;
187+ default = null;
188+ example = "https://example.com:8448/";
189+ description = ''
190+ The public-facing base URL for the client API (not including _matrix/...)
191+ '';
192+ };
193+ listeners = mkOption {
194+ type = types.listOf (types.submodule {
195+ options = {
196+ port = mkOption {
197+ type = types.int;
198+ example = 8448;
199+ description = ''
200+ The port to listen for HTTP(S) requests on.
201+ '';
202+ };
203+ bind_address = mkOption {
204+ type = types.str;
205+ default = "";
206+ example = "203.0.113.42";
207+ description = ''
208+ Local interface to listen on.
209+ The empty string will cause synapse to listen on all interfaces.
210+ '';
211+ };
212+ type = mkOption {
213+ type = types.str;
214+ default = "http";
215+ description = ''
216+ Type of listener.
217+ '';
218+ };
219+ tls = mkOption {
220+ type = types.bool;
221+ default = true;
222+ description = ''
223+ Whether to listen for HTTPS connections rather than HTTP.
224+ '';
225+ };
226+ x_forwarded = mkOption {
227+ type = types.bool;
228+ default = false;
229+ description = ''
230+ Use the X-Forwarded-For (XFF) header as the client IP and not the
231+ actual client IP.
232+ '';
233+ };
234+ resources = mkOption {
235+ type = types.listOf (types.submodule {
236+ options = {
237+ names = mkOption {
238+ type = types.listOf types.str;
239+ description = ''
240+ List of resources to host on this listener.
241+ '';
242+ example = ["client" "webclient" "federation"];
243+ };
244+ compress = mkOption {
245+ type = types.bool;
246+ description = ''
247+ Should synapse compress HTTP responses to clients that support it?
248+ This should be disabled if running synapse behind a load balancer
249+ that can do automatic compression.
250+ '';
251+ };
252+ };
253+ });
254+ description = ''
255+ List of HTTP resources to serve on this listener.
256+ '';
257+ };
258+ };
259+ });
260+ default = [{
261+ port = 8448;
262+ bind_address = "";
263+ type = "http";
264+ tls = true;
265+ x_forwarded = false;
266+ resources = [
267+ { names = ["client" "webclient"]; compress = true; }
268+ { names = ["federation"]; compress = false; }
269+ ];
270+ }];
271+ description = ''
272+ List of ports that Synapse should listen on, their purpose and their configuration.
273+ '';
274+ };
275+ verbose = mkOption {
276+ type = types.str;
277+ default = "0";
278+ description = "Logging verbosity level.";
279+ };
280+ rc_messages_per_second = mkOption {
281+ type = types.str;
282+ default = "0.2";
283+ description = "Number of messages a client can send per second";
284+ };
285+ rc_message_burst_count = mkOption {
286+ type = types.str;
287+ default = "10.0";
288+ description = "Number of message a client can send before being throttled";
289+ };
290+ federation_rc_window_size = mkOption {
291+ type = types.str;
292+ default = "1000";
293+ description = "The federation window size in milliseconds";
294+ };
295+ federation_rc_sleep_limit = mkOption {
296+ type = types.str;
297+ default = "10";
298+ description = ''
299+ The number of federation requests from a single server in a window
300+ before the server will delay processing the request.
301+ '';
302+ };
303+ federation_rc_sleep_delay = mkOption {
304+ type = types.str;
305+ default = "500";
306+ description = ''
307+ The duration in milliseconds to delay processing events from
308+ remote servers by if they go over the sleep limit.
309+ '';
310+ };
311+ federation_rc_reject_limit = mkOption {
312+ type = types.str;
313+ default = "50";
314+ description = ''
315+ The maximum number of concurrent federation requests allowed
316+ from a single server
317+ '';
318+ };
319+ federation_rc_concurrent = mkOption {
320+ type = types.str;
321+ default = "3";
322+ description = "The number of federation requests to concurrently process from a single server";
323+ };
137324 database_type = mkOption {
138325 type = types.enum [ "sqlite3" "psycopg2" ];
139326 default = "sqlite3";
@@ -150,6 +337,11 @@ in {
150337 Arguments to pass to the engine.
151338 '';
152339 };
340+ event_cache_size = mkOption {
341+ type = types.str;
342+ default = "10K";
343+ description = "Number of events to cache in memory.";
344+ };
153345 recaptcha_private_key = mkOption {
154346 type = types.str;
155347 default = "";
@@ -187,6 +379,11 @@ in {
187379 The shared secret used to compute passwords for the TURN server
188380 '';
189381 };
382+ turn_user_lifetime = mkOption {
383+ type = types.str;
384+ default = "1h";
385+ description = "How long generated TURN credentials last";
386+ };
190387 enable_registration = mkOption {
191388 type = types.bool;
192389 default = false;
@@ -195,8 +392,8 @@ in {
195392 '';
196393 };
197394 registration_shared_secret = mkOption {
198− type = types.str;
199− default = "";
395+ type = types.nullOr types.str;
396+ default = null;
200397 description = ''
201398 If set, allows registration by anyone who also has the shared
202399 secret, even if registration is otherwise disabled.
@@ -216,7 +413,7 @@ in {
216413 '';
217414 };
218415 servers = mkOption {
219− type = types.attrs;
416+ type = types.attrsOf (types.attrsOf types.str);
220417 default = {
221418 "matrix.org" = {
222419 "ed25519:auto" = "Noi6WqcDj0QmPxCNQqgezwTlBKrfqehY1u2FyWP9uYw";
@@ -226,6 +423,69 @@ in {
226423 The trusted servers to download signing keys from.
227424 '';
228425 };
426+ max_upload_size = mkOption {
427+ type = types.str;
428+ default = "10M";
429+ description = "The largest allowed upload size in bytes";
430+ };
431+ max_image_pixels = mkOption {
432+ type = types.str;
433+ default = "32M";
434+ description = "Maximum number of pixels that will be thumbnailed";
435+ };
436+ dynamic_thumbnails = mkOption {
437+ type = types.bool;
438+ default = false;
439+ description = ''
440+ Whether to generate new thumbnails on the fly to precisely match
441+ the resolution requested by the client. If true then whenever
442+ a new resolution is requested by the client the server will
443+ generate a new thumbnail. If false the server will pick a thumbnail
444+ from a precalculated list.
445+ '';
446+ };
447+ user_creation_max_duration = mkOption {
448+ type = types.str;
449+ default = "1209600000";
450+ description = ''
451+ Sets the expiry for the short term user creation in
452+ milliseconds. The default value is two weeks.
453+ '';
454+ };
455+ bcrypt_rounds = mkOption {
456+ type = types.str;
457+ default = "12";
458+ description = ''
459+ Set the number of bcrypt rounds used to generate password hash.
460+ Larger numbers increase the work factor needed to generate the hash.
461+ '';
462+ };
463+ allow_guest_access = mkOption {
464+ type = types.bool;
465+ default = false;
466+ description = ''
467+ Allows users to register as guests without a password/email/etc, and
468+ participate in rooms hosted on this server which have been made
469+ accessible to anonymous users.
470+ '';
471+ };
472+ key_refresh_interval = mkOption {
473+ type = types.str;
474+ default = "1d";
475+ description = ''
476+ How long key response published by this server is valid for.
477+ Used to set the valid_until_ts in /key/v2 APIs.
478+ Determines how quickly servers will query to check which keys
479+ are still valid.
480+ '';
481+ };
482+ app_service_config_files = mkOption {
483+ type = types.listOf types.path;
484+ default = [ ];
485+ description = ''
486+ A list of application service config file to use
487+ '';
488+ };
229489 extraConfig = mkOption {
230490 type = types.lines;
231491 default = "";
@@ -265,7 +525,7 @@ in {
265525 mkdir -p /var/lib/matrix-synapse
266526 chmod 700 /var/lib/matrix-synapse
267527 chown -R matrix-synapse:matrix-synapse /var/lib/matrix-synapse
268− ${cfg.package}/bin/homeserver --config-path ${configFile} --generate-keys
528+ ${cfg.package}/bin/homeserver --config-path ${configFile} --keys-directory /var/lib/matrix-synapse/ --generate-keys
269529 '';
270530 serviceConfig = {
271531 Type = "simple";
pkgs/servers/matrix-synapse/default.nix+5−5
@@ -1,4 +1,4 @@
1−{ pkgs, stdenv, buildPythonApplication, pythonPackages, fetchurl, fetchFromGitHub }:
1+{ lib, pkgs, stdenv, buildPythonApplication, pythonPackages, fetchurl, fetchFromGitHub }:
22let
33 matrix-angular-sdk = buildPythonApplication rec {
44 name = "matrix-angular-sdk-${version}";
@@ -12,13 +12,13 @@ let
1212in
1313buildPythonApplication rec {
1414 name = "matrix-synapse-${version}";
15− version = "0.14.0";
15+ version = "0.16.0";
1616
1717 src = fetchFromGitHub {
1818 owner = "matrix-org";
1919 repo = "synapse";
20− rev = "5fbdf2bcec40bf2f24fc0698440ee384595ff027";
21− sha256 = "1f9flb68l0bb5fkggxz1pghv72snsx6yia3s58f85z13f9vh84cb";
20+ rev = "v${version}";
21+ sha256 = "046lh9s7lpi19akqxfvr361fp8bwcz48w3sqz1vsy2z59iim9xy3";
2222 };
2323
2424 patches = [ ./matrix-synapse.patch ];
@@ -27,7 +27,7 @@ buildPythonApplication rec {
2727 blist canonicaljson daemonize dateutil frozendict pillow pybcrypt pyasn1
2828 pydenticon pymacaroons-pynacl pynacl pyopenssl pysaml2 pytz requests2
2929 service-identity signedjson systemd twisted ujson unpaddedbase64 pyyaml
30− matrix-angular-sdk
30+ matrix-angular-sdk bleach netaddr jinja2 psycopg2
3131 ];
3232
3333 # Checks fail because of Tox.