2016-01-08 15:12:00 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.matrix-synapse;
|
2017-11-04 01:20:52 +01:00
|
|
|
pg = config.services.postgresql;
|
|
|
|
usePostgresql = cfg.database_type == "psycopg2";
|
2016-01-08 15:12:00 +01:00
|
|
|
logConfigFile = pkgs.writeText "log_config.yaml" cfg.logConfig;
|
2017-04-11 18:08:51 +02:00
|
|
|
mkResource = r: ''{names: ${builtins.toJSON r.names}, compress: ${boolToString r.compress}}'';
|
|
|
|
mkListener = l: ''{port: ${toString l.port}, bind_address: "${l.bind_address}", type: ${l.type}, tls: ${boolToString l.tls}, x_forwarded: ${boolToString l.x_forwarded}, resources: [${concatStringsSep "," (map mkResource l.resources)}]}'';
|
2019-10-03 16:00:41 +02:00
|
|
|
pluginsEnv = cfg.package.python.buildEnv.override {
|
|
|
|
extraLibs = cfg.plugins;
|
|
|
|
};
|
2016-01-08 15:12:00 +01:00
|
|
|
configFile = pkgs.writeText "homeserver.yaml" ''
|
2016-10-30 02:42:01 +01:00
|
|
|
${optionalString (cfg.tls_certificate_path != null) ''
|
2016-01-08 15:12:00 +01:00
|
|
|
tls_certificate_path: "${cfg.tls_certificate_path}"
|
2016-10-30 02:42:01 +01:00
|
|
|
''}
|
2016-06-15 02:50:08 +02:00
|
|
|
${optionalString (cfg.tls_private_key_path != null) ''
|
2016-01-08 15:12:00 +01:00
|
|
|
tls_private_key_path: "${cfg.tls_private_key_path}"
|
2016-06-15 02:50:08 +02:00
|
|
|
''}
|
2016-10-30 02:42:01 +01:00
|
|
|
${optionalString (cfg.tls_dh_params_path != null) ''
|
2016-01-08 15:12:00 +01:00
|
|
|
tls_dh_params_path: "${cfg.tls_dh_params_path}"
|
2016-10-30 02:42:01 +01:00
|
|
|
''}
|
2017-04-11 18:08:51 +02:00
|
|
|
no_tls: ${boolToString cfg.no_tls}
|
2016-06-15 02:50:08 +02:00
|
|
|
${optionalString (cfg.bind_port != null) ''
|
2016-01-08 15:12:00 +01:00
|
|
|
bind_port: ${toString cfg.bind_port}
|
2016-06-15 02:50:08 +02:00
|
|
|
''}
|
|
|
|
${optionalString (cfg.unsecure_port != null) ''
|
2016-01-08 15:12:00 +01:00
|
|
|
unsecure_port: ${toString cfg.unsecure_port}
|
2016-06-15 02:50:08 +02:00
|
|
|
''}
|
|
|
|
${optionalString (cfg.bind_host != null) ''
|
2016-01-08 15:12:00 +01:00
|
|
|
bind_host: "${cfg.bind_host}"
|
2016-06-15 02:50:08 +02:00
|
|
|
''}
|
2016-01-08 15:12:00 +01:00
|
|
|
server_name: "${cfg.server_name}"
|
2018-12-19 22:37:36 +01:00
|
|
|
pid_file: "/run/matrix-synapse.pid"
|
2016-06-15 02:50:08 +02:00
|
|
|
${optionalString (cfg.public_baseurl != null) ''
|
|
|
|
public_baseurl: "${cfg.public_baseurl}"
|
|
|
|
''}
|
|
|
|
listeners: [${concatStringsSep "," (map mkListener cfg.listeners)}]
|
2016-01-08 15:12:00 +01:00
|
|
|
database: {
|
|
|
|
name: "${cfg.database_type}",
|
|
|
|
args: {
|
|
|
|
${concatStringsSep ",\n " (
|
2017-11-04 01:20:52 +01:00
|
|
|
mapAttrsToList (n: v: "\"${n}\": ${builtins.toJSON v}") cfg.database_args
|
2016-01-08 15:12:00 +01:00
|
|
|
)}
|
|
|
|
}
|
|
|
|
}
|
2016-06-15 02:50:08 +02:00
|
|
|
event_cache_size: "${cfg.event_cache_size}"
|
|
|
|
verbose: ${cfg.verbose}
|
2016-01-08 15:12:00 +01:00
|
|
|
log_config: "${logConfigFile}"
|
2016-06-15 02:50:08 +02:00
|
|
|
rc_messages_per_second: ${cfg.rc_messages_per_second}
|
|
|
|
rc_message_burst_count: ${cfg.rc_message_burst_count}
|
|
|
|
federation_rc_window_size: ${cfg.federation_rc_window_size}
|
|
|
|
federation_rc_sleep_limit: ${cfg.federation_rc_sleep_limit}
|
|
|
|
federation_rc_sleep_delay: ${cfg.federation_rc_sleep_delay}
|
|
|
|
federation_rc_reject_limit: ${cfg.federation_rc_reject_limit}
|
|
|
|
federation_rc_concurrent: ${cfg.federation_rc_concurrent}
|
2017-11-19 00:15:52 +01:00
|
|
|
media_store_path: "${cfg.dataDir}/media"
|
|
|
|
uploads_path: "${cfg.dataDir}/uploads"
|
2016-06-15 02:50:08 +02:00
|
|
|
max_upload_size: "${cfg.max_upload_size}"
|
|
|
|
max_image_pixels: "${cfg.max_image_pixels}"
|
2017-04-11 18:08:51 +02:00
|
|
|
dynamic_thumbnails: ${boolToString cfg.dynamic_thumbnails}
|
|
|
|
url_preview_enabled: ${boolToString cfg.url_preview_enabled}
|
2016-11-28 03:33:48 +01:00
|
|
|
${optionalString (cfg.url_preview_enabled == true) ''
|
|
|
|
url_preview_ip_range_blacklist: ${builtins.toJSON cfg.url_preview_ip_range_blacklist}
|
|
|
|
url_preview_ip_range_whitelist: ${builtins.toJSON cfg.url_preview_ip_range_whitelist}
|
|
|
|
url_preview_url_blacklist: ${builtins.toJSON cfg.url_preview_url_blacklist}
|
|
|
|
''}
|
2016-01-08 15:12:00 +01:00
|
|
|
recaptcha_private_key: "${cfg.recaptcha_private_key}"
|
|
|
|
recaptcha_public_key: "${cfg.recaptcha_public_key}"
|
2017-04-11 18:08:51 +02:00
|
|
|
enable_registration_captcha: ${boolToString cfg.enable_registration_captcha}
|
2016-06-15 02:50:08 +02:00
|
|
|
turn_uris: ${builtins.toJSON cfg.turn_uris}
|
2016-01-08 15:12:00 +01:00
|
|
|
turn_shared_secret: "${cfg.turn_shared_secret}"
|
2017-04-11 18:08:51 +02:00
|
|
|
enable_registration: ${boolToString cfg.enable_registration}
|
2016-06-15 02:50:08 +02:00
|
|
|
${optionalString (cfg.registration_shared_secret != null) ''
|
2016-01-08 15:12:00 +01:00
|
|
|
registration_shared_secret: "${cfg.registration_shared_secret}"
|
|
|
|
''}
|
2016-06-15 02:50:08 +02:00
|
|
|
recaptcha_siteverify_api: "https://www.google.com/recaptcha/api/siteverify"
|
|
|
|
turn_user_lifetime: "${cfg.turn_user_lifetime}"
|
|
|
|
user_creation_max_duration: ${cfg.user_creation_max_duration}
|
|
|
|
bcrypt_rounds: ${cfg.bcrypt_rounds}
|
2017-04-11 18:08:51 +02:00
|
|
|
allow_guest_access: ${boolToString cfg.allow_guest_access}
|
2019-10-05 16:53:33 +02:00
|
|
|
|
|
|
|
account_threepid_delegates:
|
|
|
|
${optionalString (cfg.account_threepid_delegates.email != null) "email: ${cfg.account_threepid_delegates.email}"}
|
|
|
|
${optionalString (cfg.account_threepid_delegates.msisdn != null) "msisdn: ${cfg.account_threepid_delegates.msisdn}"}
|
|
|
|
|
2021-05-17 13:45:28 +02:00
|
|
|
room_prejoin_state:
|
|
|
|
disable_default_event_types: ${boolToString cfg.room_prejoin_state.disable_default_event_types}
|
|
|
|
additional_event_types: ${builtins.toJSON cfg.room_prejoin_state.additional_event_types}
|
2016-09-20 06:00:51 +02:00
|
|
|
${optionalString (cfg.macaroon_secret_key != null) ''
|
|
|
|
macaroon_secret_key: "${cfg.macaroon_secret_key}"
|
|
|
|
''}
|
2017-04-11 18:08:51 +02:00
|
|
|
expire_access_token: ${boolToString cfg.expire_access_token}
|
|
|
|
enable_metrics: ${boolToString cfg.enable_metrics}
|
|
|
|
report_stats: ${boolToString cfg.report_stats}
|
2017-11-19 00:15:52 +01:00
|
|
|
signing_key_path: "${cfg.dataDir}/homeserver.signing.key"
|
2016-06-15 02:50:08 +02:00
|
|
|
key_refresh_interval: "${cfg.key_refresh_interval}"
|
2016-01-08 15:12:00 +01:00
|
|
|
perspectives:
|
|
|
|
servers: {
|
|
|
|
${concatStringsSep "},\n" (mapAttrsToList (n: v: ''
|
|
|
|
"${n}": {
|
|
|
|
"verify_keys": {
|
|
|
|
${concatStringsSep "},\n" (mapAttrsToList (n: v: ''
|
|
|
|
"${n}": {
|
|
|
|
"key": "${v}"
|
|
|
|
}'') v)}
|
|
|
|
}
|
|
|
|
'') cfg.servers)}
|
|
|
|
}
|
|
|
|
}
|
2019-10-05 16:53:33 +02:00
|
|
|
redaction_retention_period: ${toString cfg.redaction_retention_period}
|
2016-06-15 02:50:08 +02:00
|
|
|
app_service_config_files: ${builtins.toJSON cfg.app_service_config_files}
|
|
|
|
|
2016-01-08 15:12:00 +01:00
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
2020-02-18 14:50:19 +01:00
|
|
|
|
|
|
|
hasLocalPostgresDB = let args = cfg.database_args; in
|
2020-03-15 16:58:50 +01:00
|
|
|
usePostgresql && (!(args ? host) || (elem args.host [ "localhost" "127.0.0.1" "::1" ]));
|
2016-01-08 15:12:00 +01:00
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.matrix-synapse = {
|
|
|
|
enable = mkEnableOption "matrix.org synapse";
|
2021-10-08 14:45:46 +02:00
|
|
|
configFile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
readOnly = true;
|
|
|
|
description = ''
|
|
|
|
Path to the configuration file on the target system. Useful to configure e.g. workers
|
|
|
|
that also need this.
|
|
|
|
'';
|
|
|
|
};
|
2016-01-08 15:12:00 +01:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.matrix-synapse;
|
2021-10-03 18:06:03 +02:00
|
|
|
defaultText = literalExpression "pkgs.matrix-synapse";
|
2016-01-08 15:12:00 +01:00
|
|
|
description = ''
|
|
|
|
Overridable attribute of the matrix synapse server package to use.
|
|
|
|
'';
|
|
|
|
};
|
2019-10-03 16:00:41 +02:00
|
|
|
plugins = mkOption {
|
|
|
|
type = types.listOf types.package;
|
|
|
|
default = [ ];
|
2021-10-03 18:06:03 +02:00
|
|
|
example = literalExpression ''
|
2020-10-05 23:35:28 +02:00
|
|
|
with config.services.matrix-synapse.package.plugins; [
|
|
|
|
matrix-synapse-ldap3
|
|
|
|
matrix-synapse-pam
|
|
|
|
];
|
|
|
|
'';
|
2019-10-03 16:00:41 +02:00
|
|
|
description = ''
|
|
|
|
List of additional Matrix plugins to make available.
|
|
|
|
'';
|
|
|
|
};
|
2021-05-27 04:28:01 +02:00
|
|
|
withJemalloc = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to preload jemalloc to reduce memory fragmentation and overall usage.
|
|
|
|
'';
|
|
|
|
};
|
2016-01-08 15:12:00 +01:00
|
|
|
no_tls = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Don't bind to the https port
|
|
|
|
'';
|
|
|
|
};
|
2016-06-15 02:50:08 +02:00
|
|
|
bind_port = mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
|
|
|
example = 8448;
|
2016-01-08 15:12:00 +01:00
|
|
|
description = ''
|
2016-06-15 02:50:08 +02:00
|
|
|
DEPRECATED: Use listeners instead.
|
|
|
|
The port to listen for HTTPS requests on.
|
|
|
|
For when matrix traffic is sent directly to synapse.
|
2016-01-08 15:12:00 +01:00
|
|
|
'';
|
|
|
|
};
|
2016-06-15 02:50:08 +02:00
|
|
|
unsecure_port = mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
|
|
|
example = 8008;
|
2016-01-08 15:12:00 +01:00
|
|
|
description = ''
|
2016-06-15 02:50:08 +02:00
|
|
|
DEPRECATED: Use listeners instead.
|
|
|
|
The port to listen for HTTP requests on.
|
|
|
|
For when matrix traffic passes through loadbalancer that unwraps TLS.
|
2016-01-08 15:12:00 +01:00
|
|
|
'';
|
|
|
|
};
|
2016-06-15 02:50:08 +02:00
|
|
|
bind_host = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2016-01-08 15:12:00 +01:00
|
|
|
description = ''
|
2016-06-15 02:50:08 +02:00
|
|
|
DEPRECATED: Use listeners instead.
|
|
|
|
Local interface to listen on.
|
|
|
|
The empty string will cause synapse to listen on all interfaces.
|
2016-01-08 15:12:00 +01:00
|
|
|
'';
|
|
|
|
};
|
2016-06-15 02:50:08 +02:00
|
|
|
tls_certificate_path = mkOption {
|
2016-10-30 02:42:01 +01:00
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2017-11-04 01:20:52 +01:00
|
|
|
example = "${cfg.dataDir}/homeserver.tls.crt";
|
2016-01-08 15:12:00 +01:00
|
|
|
description = ''
|
2016-06-15 02:50:08 +02:00
|
|
|
PEM encoded X509 certificate for TLS.
|
|
|
|
You can replace the self-signed certificate that synapse
|
|
|
|
autogenerates on launch with your own SSL certificate + key pair
|
|
|
|
if you like. Any required intermediary certificates can be
|
|
|
|
appended after the primary certificate in hierarchical order.
|
2016-01-08 15:12:00 +01:00
|
|
|
'';
|
|
|
|
};
|
2016-06-15 02:50:08 +02:00
|
|
|
tls_private_key_path = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
2016-10-30 02:42:01 +01:00
|
|
|
default = null;
|
2017-11-04 01:20:52 +01:00
|
|
|
example = "${cfg.dataDir}/homeserver.tls.key";
|
2016-01-08 15:12:00 +01:00
|
|
|
description = ''
|
2016-06-15 02:50:08 +02:00
|
|
|
PEM encoded private key for TLS. Specify null if synapse is not
|
|
|
|
speaking TLS directly.
|
2016-01-08 15:12:00 +01:00
|
|
|
'';
|
|
|
|
};
|
2016-06-15 02:50:08 +02:00
|
|
|
tls_dh_params_path = mkOption {
|
2016-10-30 02:42:01 +01:00
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2017-11-04 01:20:52 +01:00
|
|
|
example = "${cfg.dataDir}/homeserver.tls.dh";
|
2016-01-08 15:12:00 +01:00
|
|
|
description = ''
|
2016-06-15 02:50:08 +02:00
|
|
|
PEM dh parameters for ephemeral keys
|
2016-01-08 15:12:00 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
server_name = mkOption {
|
|
|
|
type = types.str;
|
2016-06-15 02:50:08 +02:00
|
|
|
example = "example.com";
|
2017-11-04 14:16:31 +01:00
|
|
|
default = config.networking.hostName;
|
2016-01-08 15:12:00 +01:00
|
|
|
description = ''
|
|
|
|
The domain name of the server, with optional explicit port.
|
2021-09-03 03:27:00 +02:00
|
|
|
This is used by remote servers to look up the server address.
|
2016-01-08 15:12:00 +01:00
|
|
|
This is also the last part of your UserID.
|
2021-09-03 03:27:00 +02:00
|
|
|
|
|
|
|
The server_name cannot be changed later so it is important to configure this correctly before you start Synapse.
|
2016-01-08 15:12:00 +01:00
|
|
|
'';
|
|
|
|
};
|
2016-06-15 02:50:08 +02:00
|
|
|
public_baseurl = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "https://example.com:8448/";
|
|
|
|
description = ''
|
|
|
|
The public-facing base URL for the client API (not including _matrix/...)
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
listeners = mkOption {
|
|
|
|
type = types.listOf (types.submodule {
|
|
|
|
options = {
|
|
|
|
port = mkOption {
|
2021-05-25 19:29:16 +02:00
|
|
|
type = types.port;
|
2016-06-15 02:50:08 +02:00
|
|
|
example = 8448;
|
|
|
|
description = ''
|
|
|
|
The port to listen for HTTP(S) requests on.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
bind_address = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
example = "203.0.113.42";
|
|
|
|
description = ''
|
|
|
|
Local interface to listen on.
|
|
|
|
The empty string will cause synapse to listen on all interfaces.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
type = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "http";
|
|
|
|
description = ''
|
|
|
|
Type of listener.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
tls = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to listen for HTTPS connections rather than HTTP.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
x_forwarded = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Use the X-Forwarded-For (XFF) header as the client IP and not the
|
|
|
|
actual client IP.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
resources = mkOption {
|
|
|
|
type = types.listOf (types.submodule {
|
|
|
|
options = {
|
|
|
|
names = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
description = ''
|
|
|
|
List of resources to host on this listener.
|
|
|
|
'';
|
|
|
|
example = ["client" "webclient" "federation"];
|
|
|
|
};
|
|
|
|
compress = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Should synapse compress HTTP responses to clients that support it?
|
|
|
|
This should be disabled if running synapse behind a load balancer
|
|
|
|
that can do automatic compression.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
description = ''
|
|
|
|
List of HTTP resources to serve on this listener.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
default = [{
|
|
|
|
port = 8448;
|
|
|
|
bind_address = "";
|
|
|
|
type = "http";
|
|
|
|
tls = true;
|
|
|
|
x_forwarded = false;
|
|
|
|
resources = [
|
|
|
|
{ names = ["client" "webclient"]; compress = true; }
|
|
|
|
{ names = ["federation"]; compress = false; }
|
|
|
|
];
|
|
|
|
}];
|
|
|
|
description = ''
|
|
|
|
List of ports that Synapse should listen on, their purpose and their configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
verbose = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "0";
|
|
|
|
description = "Logging verbosity level.";
|
|
|
|
};
|
|
|
|
rc_messages_per_second = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "0.2";
|
|
|
|
description = "Number of messages a client can send per second";
|
|
|
|
};
|
|
|
|
rc_message_burst_count = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "10.0";
|
|
|
|
description = "Number of message a client can send before being throttled";
|
|
|
|
};
|
|
|
|
federation_rc_window_size = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "1000";
|
|
|
|
description = "The federation window size in milliseconds";
|
|
|
|
};
|
|
|
|
federation_rc_sleep_limit = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "10";
|
|
|
|
description = ''
|
|
|
|
The number of federation requests from a single server in a window
|
|
|
|
before the server will delay processing the request.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
federation_rc_sleep_delay = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "500";
|
|
|
|
description = ''
|
|
|
|
The duration in milliseconds to delay processing events from
|
|
|
|
remote servers by if they go over the sleep limit.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
federation_rc_reject_limit = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "50";
|
|
|
|
description = ''
|
|
|
|
The maximum number of concurrent federation requests allowed
|
|
|
|
from a single server
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
federation_rc_concurrent = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "3";
|
|
|
|
description = "The number of federation requests to concurrently process from a single server";
|
|
|
|
};
|
2016-01-08 15:12:00 +01:00
|
|
|
database_type = mkOption {
|
|
|
|
type = types.enum [ "sqlite3" "psycopg2" ];
|
2018-07-25 22:22:54 +02:00
|
|
|
default = if versionAtLeast config.system.stateVersion "18.03"
|
2017-11-04 14:11:49 +01:00
|
|
|
then "psycopg2"
|
|
|
|
else "sqlite3";
|
2016-01-08 15:12:00 +01:00
|
|
|
description = ''
|
|
|
|
The database engine name. Can be sqlite or psycopg2.
|
|
|
|
'';
|
|
|
|
};
|
2017-11-04 01:20:52 +01:00
|
|
|
database_name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "matrix-synapse";
|
|
|
|
description = "Database name.";
|
|
|
|
};
|
|
|
|
database_user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "matrix-synapse";
|
|
|
|
description = "Database user name.";
|
|
|
|
};
|
2016-01-08 15:12:00 +01:00
|
|
|
database_args = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = {
|
2017-11-04 01:20:52 +01:00
|
|
|
sqlite3 = { database = "${cfg.dataDir}/homeserver.db"; };
|
|
|
|
psycopg2 = {
|
|
|
|
user = cfg.database_user;
|
|
|
|
database = cfg.database_name;
|
|
|
|
};
|
2019-08-13 23:52:01 +02:00
|
|
|
}.${cfg.database_type};
|
2016-01-08 15:12:00 +01:00
|
|
|
description = ''
|
|
|
|
Arguments to pass to the engine.
|
|
|
|
'';
|
|
|
|
};
|
2016-06-15 02:50:08 +02:00
|
|
|
event_cache_size = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "10K";
|
|
|
|
description = "Number of events to cache in memory.";
|
|
|
|
};
|
2016-11-28 03:33:48 +01:00
|
|
|
url_preview_enabled = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Is the preview URL API enabled? If enabled, you *must* specify an
|
|
|
|
explicit url_preview_ip_range_blacklist of IPs that the spider is
|
|
|
|
denied from accessing.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
url_preview_ip_range_blacklist = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2018-05-06 11:49:04 +02:00
|
|
|
default = [
|
|
|
|
"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"
|
2019-10-03 18:01:59 +02:00
|
|
|
"::1/128"
|
|
|
|
"fe80::/64"
|
|
|
|
"fc00::/7"
|
2018-05-06 11:49:04 +02:00
|
|
|
];
|
2016-11-28 03:33:48 +01:00
|
|
|
description = ''
|
|
|
|
List of IP address CIDR ranges that the URL preview spider is denied
|
|
|
|
from accessing.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
url_preview_ip_range_whitelist = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
List of IP address CIDR ranges that the URL preview spider is allowed
|
|
|
|
to access even if they are specified in
|
|
|
|
url_preview_ip_range_blacklist.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
url_preview_url_blacklist = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2018-05-06 11:49:04 +02:00
|
|
|
default = [];
|
2016-11-28 03:33:48 +01:00
|
|
|
description = ''
|
|
|
|
Optional list of URL matches that the URL preview spider is
|
|
|
|
denied from accessing.
|
|
|
|
'';
|
|
|
|
};
|
2016-01-08 15:12:00 +01:00
|
|
|
recaptcha_private_key = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
This Home Server's ReCAPTCHA private key.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
recaptcha_public_key = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
This Home Server's ReCAPTCHA public key.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
enable_registration_captcha = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enables ReCaptcha checks when registering, preventing signup
|
|
|
|
unless a captcha is answered. Requires a valid ReCaptcha
|
|
|
|
public/private key.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
turn_uris = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
The public URIs of the TURN server to give to clients
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
turn_shared_secret = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
The shared secret used to compute passwords for the TURN server
|
|
|
|
'';
|
|
|
|
};
|
2016-06-15 02:50:08 +02:00
|
|
|
turn_user_lifetime = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "1h";
|
|
|
|
description = "How long generated TURN credentials last";
|
|
|
|
};
|
2016-01-08 15:12:00 +01:00
|
|
|
enable_registration = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable registration for new users.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
registration_shared_secret = mkOption {
|
2016-06-15 02:50:08 +02:00
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2016-01-08 15:12:00 +01:00
|
|
|
description = ''
|
|
|
|
If set, allows registration by anyone who also has the shared
|
|
|
|
secret, even if registration is otherwise disabled.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
enable_metrics = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable collection and rendering of performance metrics
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
report_stats = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2021-01-24 10:19:10 +01:00
|
|
|
description = "";
|
2016-01-08 15:12:00 +01:00
|
|
|
};
|
|
|
|
servers = mkOption {
|
2016-06-15 02:50:08 +02:00
|
|
|
type = types.attrsOf (types.attrsOf types.str);
|
2016-01-08 15:12:00 +01:00
|
|
|
default = {
|
|
|
|
"matrix.org" = {
|
|
|
|
"ed25519:auto" = "Noi6WqcDj0QmPxCNQqgezwTlBKrfqehY1u2FyWP9uYw";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
description = ''
|
|
|
|
The trusted servers to download signing keys from.
|
|
|
|
'';
|
|
|
|
};
|
2016-06-15 02:50:08 +02:00
|
|
|
max_upload_size = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "10M";
|
|
|
|
description = "The largest allowed upload size in bytes";
|
|
|
|
};
|
|
|
|
max_image_pixels = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "32M";
|
|
|
|
description = "Maximum number of pixels that will be thumbnailed";
|
|
|
|
};
|
|
|
|
dynamic_thumbnails = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to generate new thumbnails on the fly to precisely match
|
|
|
|
the resolution requested by the client. If true then whenever
|
|
|
|
a new resolution is requested by the client the server will
|
|
|
|
generate a new thumbnail. If false the server will pick a thumbnail
|
|
|
|
from a precalculated list.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
user_creation_max_duration = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "1209600000";
|
|
|
|
description = ''
|
|
|
|
Sets the expiry for the short term user creation in
|
|
|
|
milliseconds. The default value is two weeks.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
bcrypt_rounds = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "12";
|
|
|
|
description = ''
|
|
|
|
Set the number of bcrypt rounds used to generate password hash.
|
|
|
|
Larger numbers increase the work factor needed to generate the hash.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
allow_guest_access = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Allows users to register as guests without a password/email/etc, and
|
|
|
|
participate in rooms hosted on this server which have been made
|
|
|
|
accessible to anonymous users.
|
|
|
|
'';
|
|
|
|
};
|
2019-10-05 16:53:33 +02:00
|
|
|
account_threepid_delegates.email = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2016-09-20 06:00:51 +02:00
|
|
|
description = ''
|
2019-10-05 16:53:33 +02:00
|
|
|
Delegate email sending to https://example.org
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
account_threepid_delegates.msisdn = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Delegate SMS sending to this local process (https://localhost:8090)
|
2016-09-20 06:00:51 +02:00
|
|
|
'';
|
|
|
|
};
|
2021-05-17 13:45:28 +02:00
|
|
|
room_prejoin_state.additional_event_types = mkOption {
|
|
|
|
default = [];
|
2016-09-20 06:00:51 +02:00
|
|
|
type = types.listOf types.str;
|
|
|
|
description = ''
|
2021-05-17 13:45:28 +02:00
|
|
|
Additional events to share with users who received an invite.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
room_prejoin_state.disable_default_event_types = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Whether to disable the default state-event types for users invited to a room.
|
|
|
|
These are:
|
|
|
|
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem><para>m.room.join_rules</para></listitem>
|
|
|
|
<listitem><para>m.room.canonical_alias</para></listitem>
|
|
|
|
<listitem><para>m.room.avatar</para></listitem>
|
|
|
|
<listitem><para>m.room.encryption</para></listitem>
|
|
|
|
<listitem><para>m.room.name</para></listitem>
|
|
|
|
<listitem><para>m.room.create</para></listitem>
|
|
|
|
</itemizedlist>
|
2016-09-20 06:00:51 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
macaroon_secret_key = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Secret key for authentication tokens
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
expire_access_token = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable access token expiration.
|
|
|
|
'';
|
|
|
|
};
|
2016-06-15 02:50:08 +02:00
|
|
|
key_refresh_interval = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "1d";
|
|
|
|
description = ''
|
|
|
|
How long key response published by this server is valid for.
|
|
|
|
Used to set the valid_until_ts in /key/v2 APIs.
|
|
|
|
Determines how quickly servers will query to check which keys
|
|
|
|
are still valid.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
app_service_config_files = mkOption {
|
|
|
|
type = types.listOf types.path;
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
A list of application service config file to use
|
|
|
|
'';
|
|
|
|
};
|
2019-10-05 16:53:33 +02:00
|
|
|
redaction_retention_period = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 7;
|
|
|
|
description = ''
|
|
|
|
How long to keep redacted events in unredacted form in the database.
|
|
|
|
'';
|
|
|
|
};
|
2016-01-08 15:12:00 +01:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Extra config options for matrix-synapse.
|
|
|
|
'';
|
|
|
|
};
|
2018-01-07 21:13:48 +01:00
|
|
|
extraConfigFiles = mkOption {
|
|
|
|
type = types.listOf types.path;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
Extra config files to include.
|
|
|
|
|
|
|
|
The configuration files will be included based on the command line
|
|
|
|
argument --config-path. This allows to configure secrets without
|
|
|
|
having to go through the Nix store, e.g. based on deployment keys if
|
|
|
|
NixOPS is in use.
|
|
|
|
'';
|
|
|
|
};
|
2016-01-08 15:12:00 +01:00
|
|
|
logConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = readFile ./matrix-synapse-log_config.yaml;
|
|
|
|
description = ''
|
|
|
|
A yaml python logging config file
|
|
|
|
'';
|
|
|
|
};
|
2017-11-19 00:15:52 +01:00
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/matrix-synapse";
|
|
|
|
description = ''
|
|
|
|
The directory where matrix-synapse stores its stateful data such as
|
|
|
|
certificates, media and uploads.
|
|
|
|
'';
|
|
|
|
};
|
2016-01-08 15:12:00 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2020-02-18 14:50:19 +01:00
|
|
|
assertions = [
|
|
|
|
{ assertion = hasLocalPostgresDB -> config.services.postgresql.enable;
|
|
|
|
message = ''
|
|
|
|
Cannot deploy matrix-synapse with a configuration for a local postgresql database
|
|
|
|
and a missing postgresql service. Since 20.03 it's mandatory to manually configure the
|
|
|
|
database (please read the thread in https://github.com/NixOS/nixpkgs/pull/80447 for
|
|
|
|
further reference).
|
|
|
|
|
|
|
|
If you
|
|
|
|
- try to deploy a fresh synapse, you need to configure the database yourself. An example
|
|
|
|
for this can be found in <nixpkgs/nixos/tests/matrix-synapse.nix>
|
|
|
|
- update your existing matrix-synapse instance, you simply need to add `services.postgresql.enable = true`
|
|
|
|
to your configuration.
|
|
|
|
|
|
|
|
For further information about this update, please read the release-notes of 20.03 carefully.
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2021-10-08 14:45:46 +02:00
|
|
|
services.matrix-synapse.configFile = "${configFile}";
|
|
|
|
|
2020-08-07 15:43:58 +02:00
|
|
|
users.users.matrix-synapse = {
|
2021-05-22 00:47:54 +02:00
|
|
|
group = "matrix-synapse";
|
|
|
|
home = cfg.dataDir;
|
|
|
|
createHome = true;
|
|
|
|
shell = "${pkgs.bash}/bin/bash";
|
|
|
|
uid = config.ids.uids.matrix-synapse;
|
|
|
|
};
|
2016-01-08 15:12:00 +01:00
|
|
|
|
2019-09-14 19:51:29 +02:00
|
|
|
users.groups.matrix-synapse = {
|
|
|
|
gid = config.ids.gids.matrix-synapse;
|
|
|
|
};
|
2016-01-08 15:12:00 +01:00
|
|
|
|
2019-02-23 20:58:28 +01:00
|
|
|
systemd.services.matrix-synapse = {
|
2017-05-16 01:30:30 +02:00
|
|
|
description = "Synapse Matrix homeserver";
|
2020-02-18 14:50:19 +01:00
|
|
|
after = [ "network.target" ] ++ optional hasLocalPostgresDB "postgresql.service";
|
2016-01-08 15:12:00 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
preStart = ''
|
2019-02-23 20:58:28 +01:00
|
|
|
${cfg.package}/bin/homeserver \
|
2016-10-30 02:42:01 +01:00
|
|
|
--config-path ${configFile} \
|
2017-11-19 00:15:52 +01:00
|
|
|
--keys-directory ${cfg.dataDir} \
|
2016-10-30 02:42:01 +01:00
|
|
|
--generate-keys
|
2016-01-08 15:12:00 +01:00
|
|
|
'';
|
2021-05-27 04:28:01 +02:00
|
|
|
environment = {
|
|
|
|
PYTHONPATH = makeSearchPathOutput "lib" cfg.package.python.sitePackages [ pluginsEnv ];
|
|
|
|
} // optionalAttrs (cfg.withJemalloc) {
|
|
|
|
LD_PRELOAD = "${pkgs.jemalloc}/lib/libjemalloc.so";
|
|
|
|
};
|
2016-01-08 15:12:00 +01:00
|
|
|
serviceConfig = {
|
2019-08-16 12:49:34 +02:00
|
|
|
Type = "notify";
|
2016-01-08 15:12:00 +01:00
|
|
|
User = "matrix-synapse";
|
|
|
|
Group = "matrix-synapse";
|
2017-11-19 00:15:52 +01:00
|
|
|
WorkingDirectory = cfg.dataDir;
|
2021-05-22 00:47:54 +02:00
|
|
|
ExecStartPre = [ ("+" + (pkgs.writeShellScript "matrix-synapse-fix-permissions" ''
|
|
|
|
chown matrix-synapse:matrix-synapse ${cfg.dataDir}/homeserver.signing.key
|
|
|
|
chmod 0600 ${cfg.dataDir}/homeserver.signing.key
|
|
|
|
'')) ];
|
2018-01-07 21:13:48 +01:00
|
|
|
ExecStart = ''
|
2019-02-23 20:58:28 +01:00
|
|
|
${cfg.package}/bin/homeserver \
|
2018-01-07 21:13:48 +01:00
|
|
|
${ concatMapStringsSep "\n " (x: "--config-path ${x} \\") ([ configFile ] ++ cfg.extraConfigFiles) }
|
|
|
|
--keys-directory ${cfg.dataDir}
|
|
|
|
'';
|
2020-11-24 16:29:28 +01:00
|
|
|
ExecReload = "${pkgs.util-linux}/bin/kill -HUP $MAINPID";
|
2017-05-16 01:30:30 +02:00
|
|
|
Restart = "on-failure";
|
2021-05-22 00:47:54 +02:00
|
|
|
UMask = "0077";
|
2016-01-08 15:12:00 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2019-10-05 16:53:33 +02:00
|
|
|
|
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "services" "matrix-synapse" "trusted_third_party_id_servers" ] ''
|
|
|
|
The `trusted_third_party_id_servers` option as been removed in `matrix-synapse` v1.4.0
|
|
|
|
as the behavior is now obsolete.
|
|
|
|
'')
|
2020-02-18 14:50:19 +01:00
|
|
|
(mkRemovedOptionModule [ "services" "matrix-synapse" "create_local_database" ] ''
|
|
|
|
Database configuration must be done manually. An exemplary setup is demonstrated in
|
|
|
|
<nixpkgs/nixos/tests/matrix-synapse.nix>
|
|
|
|
'')
|
2020-02-27 22:26:11 +01:00
|
|
|
(mkRemovedOptionModule [ "services" "matrix-synapse" "web_client" ] "")
|
2021-05-17 13:45:28 +02:00
|
|
|
(mkRemovedOptionModule [ "services" "matrix-synapse" "room_invite_state_types" ] ''
|
|
|
|
You may add additional event types via
|
|
|
|
`services.matrix-synapse.room_prejoin_state.additional_event_types` and
|
|
|
|
disable the default events via
|
|
|
|
`services.matrix-synapse.room_prejoin_state.disable_default_event_types`.
|
|
|
|
'')
|
2019-10-05 16:53:33 +02:00
|
|
|
];
|
|
|
|
|
2020-03-15 16:58:50 +01:00
|
|
|
meta.doc = ./matrix-synapse.xml;
|
2020-06-12 03:05:26 +02:00
|
|
|
meta.maintainers = teams.matrix.members;
|
2020-03-15 16:58:50 +01:00
|
|
|
|
2016-01-08 15:12:00 +01:00
|
|
|
}
|