2021-05-03 20:48:10 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
2021-05-20 23:08:51 +00:00
|
|
|
cfg = config.services.dendrite;
|
2021-05-03 20:48:10 +00:00
|
|
|
settingsFormat = pkgs.formats.yaml { };
|
|
|
|
configurationYaml = settingsFormat.generate "dendrite.yaml" cfg.settings;
|
2021-05-20 23:08:51 +00:00
|
|
|
workingDir = "/var/lib/dendrite";
|
2021-05-03 20:48:10 +00:00
|
|
|
in
|
|
|
|
{
|
2021-05-20 23:08:51 +00:00
|
|
|
options.services.dendrite = {
|
2021-05-03 20:48:10 +00:00
|
|
|
enable = lib.mkEnableOption "matrix.org dendrite";
|
|
|
|
httpPort = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.port;
|
|
|
|
default = 8008;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-05-03 20:48:10 +00:00
|
|
|
The port to listen for HTTP requests on.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
httpsPort = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.port;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-05-03 20:48:10 +00:00
|
|
|
The port to listen for HTTPS requests on.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
tlsCert = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.path;
|
2021-05-20 23:08:51 +00:00
|
|
|
example = "/var/lib/dendrite/server.cert";
|
2021-05-03 20:48:10 +00:00
|
|
|
default = null;
|
2022-08-21 13:32:41 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-05-03 20:48:10 +00:00
|
|
|
The path to the TLS certificate.
|
|
|
|
|
2022-08-21 13:32:41 +00:00
|
|
|
```
|
2021-05-20 23:08:51 +00:00
|
|
|
nix-shell -p dendrite --command "generate-keys --tls-cert server.crt --tls-key server.key"
|
2022-08-21 13:32:41 +00:00
|
|
|
```
|
2021-05-03 20:48:10 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
tlsKey = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.path;
|
2021-05-20 23:08:51 +00:00
|
|
|
example = "/var/lib/dendrite/server.key";
|
2021-05-03 20:48:10 +00:00
|
|
|
default = null;
|
2022-08-21 13:32:41 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-05-03 20:48:10 +00:00
|
|
|
The path to the TLS key.
|
|
|
|
|
2022-08-21 13:32:41 +00:00
|
|
|
```
|
2021-05-20 23:08:51 +00:00
|
|
|
nix-shell -p dendrite --command "generate-keys --tls-cert server.crt --tls-key server.key"
|
2022-08-21 13:32:41 +00:00
|
|
|
```
|
2021-05-03 20:48:10 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
environmentFile = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.path;
|
2021-05-20 23:08:51 +00:00
|
|
|
example = "/var/lib/dendrite/registration_secret";
|
2021-05-03 20:48:10 +00:00
|
|
|
default = null;
|
|
|
|
description = ''
|
2022-08-21 13:32:41 +00:00
|
|
|
Environment file as defined in <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
|
2021-05-03 20:48:10 +00:00
|
|
|
Secrets may be passed to the service without adding them to the world-readable
|
|
|
|
Nix store, by specifying placeholder variables as the option value in Nix and
|
|
|
|
setting these variables accordingly in the environment file. Currently only used
|
|
|
|
for the registration secret to allow secure registration when
|
|
|
|
client_api.registration_disabled is true.
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
# snippet of dendrite-related config
|
2021-05-20 23:08:51 +00:00
|
|
|
services.dendrite.settings.client_api.registration_shared_secret = "$REGISTRATION_SHARED_SECRET";
|
2021-05-03 20:48:10 +00:00
|
|
|
</programlisting>
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
# content of the environment file
|
|
|
|
REGISTRATION_SHARED_SECRET=verysecretpassword
|
|
|
|
</programlisting>
|
|
|
|
|
|
|
|
Note that this file needs to be available on the host on which
|
|
|
|
<literal>dendrite</literal> is running.
|
|
|
|
'';
|
|
|
|
};
|
2022-06-16 17:23:12 +00:00
|
|
|
loadCredential = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
|
|
|
default = [ ];
|
|
|
|
example = [ "private_key:/path/to/my_private_key" ];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-06-16 17:23:12 +00:00
|
|
|
This can be used to pass secrets to the systemd service without adding them to
|
|
|
|
the nix store.
|
|
|
|
To use the example setting, see the example of
|
2022-08-12 12:06:08 +00:00
|
|
|
{option}`services.dendrite.settings.global.private_key`.
|
2022-06-16 17:23:12 +00:00
|
|
|
See the LoadCredential section of systemd.exec manual for more information.
|
|
|
|
'';
|
|
|
|
};
|
2021-05-03 20:48:10 +00:00
|
|
|
settings = lib.mkOption {
|
|
|
|
type = lib.types.submodule {
|
|
|
|
freeformType = settingsFormat.type;
|
|
|
|
options.global = {
|
|
|
|
server_name = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
example = "example.com";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-05-03 20:48:10 +00:00
|
|
|
The domain name of the server, with optional explicit port.
|
|
|
|
This is used by remote servers to connect to this server.
|
|
|
|
This is also the last part of your UserID.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
private_key = lib.mkOption {
|
2022-06-16 17:23:12 +00:00
|
|
|
type = lib.types.either
|
|
|
|
lib.types.path
|
|
|
|
(lib.types.strMatching "^\\$CREDENTIALS_DIRECTORY/.+");
|
|
|
|
example = "$CREDENTIALS_DIRECTORY/private_key";
|
2022-08-21 13:32:41 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-05-03 20:48:10 +00:00
|
|
|
The path to the signing private key file, used to sign
|
|
|
|
requests and events.
|
|
|
|
|
2022-08-21 13:32:41 +00:00
|
|
|
```
|
2021-05-20 23:08:51 +00:00
|
|
|
nix-shell -p dendrite --command "generate-keys --private-key matrix_key.pem"
|
2022-08-21 13:32:41 +00:00
|
|
|
```
|
2021-05-03 20:48:10 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
trusted_third_party_id_servers = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
|
|
|
example = [ "matrix.org" ];
|
|
|
|
default = [ "matrix.org" "vector.im" ];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-05-03 20:48:10 +00:00
|
|
|
Lists of domains that the server will trust as identity
|
|
|
|
servers to verify third party identifiers such as phone
|
|
|
|
numbers and email addresses
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2022-03-10 19:12:11 +00:00
|
|
|
options.app_service_api.database = {
|
|
|
|
connection_string = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "file:federationapi.db";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-03-10 19:12:11 +00:00
|
|
|
Database for the Appservice API.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2021-05-03 20:48:10 +00:00
|
|
|
options.client_api = {
|
|
|
|
registration_disabled = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = true;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-05-03 20:48:10 +00:00
|
|
|
Whether to disable user registration to the server
|
|
|
|
without the shared secret.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2022-03-10 19:12:11 +00:00
|
|
|
options.federation_api.database = {
|
|
|
|
connection_string = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "file:federationapi.db";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-03-10 19:12:11 +00:00
|
|
|
Database for the Federation API.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
options.key_server.database = {
|
|
|
|
connection_string = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "file:keyserver.db";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-03-10 19:12:11 +00:00
|
|
|
Database for the Key Server (for end-to-end encryption).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
options.media_api = {
|
|
|
|
database = {
|
|
|
|
connection_string = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "file:mediaapi.db";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-03-10 19:12:11 +00:00
|
|
|
Database for the Media API.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
base_path = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "${workingDir}/media_store";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-03-10 19:12:11 +00:00
|
|
|
Storage path for uploaded media.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
options.room_server.database = {
|
|
|
|
connection_string = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "file:roomserver.db";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-03-10 19:12:11 +00:00
|
|
|
Database for the Room Server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
options.sync_api.database = {
|
|
|
|
connection_string = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "file:syncserver.db";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-03-10 19:12:11 +00:00
|
|
|
Database for the Sync API.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
options.user_api = {
|
|
|
|
account_database = {
|
|
|
|
connection_string = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "file:userapi_accounts.db";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-03-10 19:12:11 +00:00
|
|
|
Database for the User API, accounts.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
device_database = {
|
|
|
|
connection_string = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "file:userapi_devices.db";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-03-10 19:12:11 +00:00
|
|
|
Database for the User API, devices.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
options.mscs = {
|
|
|
|
database = {
|
|
|
|
connection_string = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "file:mscs.db";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-03-10 19:12:11 +00:00
|
|
|
Database for exerimental MSC's.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2021-05-03 20:48:10 +00:00
|
|
|
};
|
|
|
|
default = { };
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-05-03 20:48:10 +00:00
|
|
|
Configuration for dendrite, see:
|
2022-08-12 12:06:08 +00:00
|
|
|
<https://github.com/matrix-org/dendrite/blob/master/dendrite-config.yaml>
|
2021-05-03 20:48:10 +00:00
|
|
|
for available options with which to populate settings.
|
|
|
|
'';
|
|
|
|
};
|
2022-05-18 14:49:53 +00:00
|
|
|
openRegistration = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-05-18 14:49:53 +00:00
|
|
|
Allow open registration without secondary verification (reCAPTCHA).
|
|
|
|
'';
|
|
|
|
};
|
2021-05-03 20:48:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
assertions = [{
|
|
|
|
assertion = cfg.httpsPort != null -> (cfg.tlsCert != null && cfg.tlsKey != null);
|
|
|
|
message = ''
|
|
|
|
If Dendrite is configured to use https, tlsCert and tlsKey must be provided.
|
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
nix-shell -p dendrite --command "generate-keys --tls-cert server.crt --tls-key server.key"
|
2021-05-03 20:48:10 +00:00
|
|
|
'';
|
|
|
|
}];
|
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
systemd.services.dendrite = {
|
2021-05-03 20:48:10 +00:00
|
|
|
description = "Dendrite Matrix homeserver";
|
|
|
|
after = [
|
|
|
|
"network.target"
|
|
|
|
];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
DynamicUser = true;
|
2021-05-20 23:08:51 +00:00
|
|
|
StateDirectory = "dendrite";
|
2021-05-03 20:48:10 +00:00
|
|
|
WorkingDirectory = workingDir;
|
2021-05-20 23:08:51 +00:00
|
|
|
RuntimeDirectory = "dendrite";
|
2021-05-03 20:48:10 +00:00
|
|
|
RuntimeDirectoryMode = "0700";
|
2022-04-27 09:35:20 +00:00
|
|
|
LimitNOFILE = 65535;
|
2021-05-03 20:48:10 +00:00
|
|
|
EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile;
|
2022-06-16 17:23:12 +00:00
|
|
|
LoadCredential = cfg.loadCredential;
|
2022-03-30 09:31:56 +00:00
|
|
|
ExecStartPre = ''
|
|
|
|
${pkgs.envsubst}/bin/envsubst \
|
|
|
|
-i ${configurationYaml} \
|
|
|
|
-o /run/dendrite/dendrite.yaml
|
|
|
|
'';
|
2021-05-03 20:48:10 +00:00
|
|
|
ExecStart = lib.strings.concatStringsSep " " ([
|
2021-05-20 23:08:51 +00:00
|
|
|
"${pkgs.dendrite}/bin/dendrite-monolith-server"
|
|
|
|
"--config /run/dendrite/dendrite.yaml"
|
2021-05-03 20:48:10 +00:00
|
|
|
] ++ lib.optionals (cfg.httpPort != null) [
|
|
|
|
"--http-bind-address :${builtins.toString cfg.httpPort}"
|
|
|
|
] ++ lib.optionals (cfg.httpsPort != null) [
|
|
|
|
"--https-bind-address :${builtins.toString cfg.httpsPort}"
|
|
|
|
"--tls-cert ${cfg.tlsCert}"
|
|
|
|
"--tls-key ${cfg.tlsKey}"
|
2022-05-18 14:49:53 +00:00
|
|
|
] ++ lib.optionals cfg.openRegistration [
|
|
|
|
"--really-enable-open-registration"
|
2021-05-03 20:48:10 +00:00
|
|
|
]);
|
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
|
|
Restart = "on-failure";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
meta.maintainers = lib.teams.matrix.members;
|
|
|
|
}
|