2021-09-02 09:55:51 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.services.matrix-conduit;
|
|
|
|
|
|
|
|
format = pkgs.formats.toml {};
|
|
|
|
configFile = format.generate "conduit.toml" cfg.settings;
|
|
|
|
in
|
|
|
|
{
|
2024-08-24 20:05:36 +00:00
|
|
|
meta.maintainers = with lib.maintainers; [ pstn ];
|
2021-09-02 09:55:51 +00:00
|
|
|
options.services.matrix-conduit = {
|
2024-08-24 20:05:36 +00:00
|
|
|
enable = lib.mkEnableOption "matrix-conduit";
|
2021-09-02 09:55:51 +00:00
|
|
|
|
2024-08-24 20:05:36 +00:00
|
|
|
extraEnvironment = lib.mkOption {
|
|
|
|
type = lib.types.attrsOf lib.types.str;
|
2021-09-02 09:55:51 +00:00
|
|
|
description = "Extra Environment variables to pass to the conduit server.";
|
|
|
|
default = {};
|
|
|
|
example = { RUST_BACKTRACE="yes"; };
|
|
|
|
};
|
|
|
|
|
2024-08-24 20:05:36 +00:00
|
|
|
package = lib.mkPackageOption pkgs "matrix-conduit" { };
|
2021-09-02 09:55:51 +00:00
|
|
|
|
2024-08-24 20:05:36 +00:00
|
|
|
settings = lib.mkOption {
|
|
|
|
type = lib.types.submodule {
|
2021-09-02 09:55:51 +00:00
|
|
|
freeformType = format.type;
|
|
|
|
options = {
|
2024-08-24 20:05:36 +00:00
|
|
|
global.server_name = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2021-09-02 09:55:51 +00:00
|
|
|
example = "example.com";
|
|
|
|
description = "The server_name is the name of this server. It is used as a suffix for user # and room ids.";
|
|
|
|
};
|
2024-08-24 20:05:36 +00:00
|
|
|
global.port = lib.mkOption {
|
|
|
|
type = lib.types.port;
|
2021-09-02 09:55:51 +00:00
|
|
|
default = 6167;
|
|
|
|
description = "The port Conduit will be running on. You need to set up a reverse proxy in your web server (e.g. apache or nginx), so all requests to /_matrix on port 443 and 8448 will be forwarded to the Conduit instance running on this port";
|
|
|
|
};
|
2024-08-24 20:05:36 +00:00
|
|
|
global.max_request_size = lib.mkOption {
|
|
|
|
type = lib.types.ints.positive;
|
2021-09-02 09:55:51 +00:00
|
|
|
default = 20000000;
|
|
|
|
description = "Max request size in bytes. Don't forget to also change it in the proxy.";
|
|
|
|
};
|
2024-08-24 20:05:36 +00:00
|
|
|
global.allow_registration = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2021-09-02 09:55:51 +00:00
|
|
|
default = false;
|
|
|
|
description = "Whether new users can register on this server.";
|
|
|
|
};
|
2024-08-24 20:05:36 +00:00
|
|
|
global.allow_encryption = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2021-09-02 09:55:51 +00:00
|
|
|
default = true;
|
|
|
|
description = "Whether new encrypted rooms can be created. Note: existing rooms will continue to work.";
|
|
|
|
};
|
2024-08-24 20:05:36 +00:00
|
|
|
global.allow_federation = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2021-09-02 09:55:51 +00:00
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether this server federates with other servers.
|
|
|
|
'';
|
|
|
|
};
|
2024-08-24 20:05:36 +00:00
|
|
|
global.trusted_servers = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
2021-09-02 09:55:51 +00:00
|
|
|
default = [ "matrix.org" ];
|
|
|
|
description = "Servers trusted with signing server keys.";
|
|
|
|
};
|
2024-08-24 20:05:36 +00:00
|
|
|
global.address = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2021-09-02 09:55:51 +00:00
|
|
|
default = "::1";
|
|
|
|
description = "Address to listen on for connections by the reverse proxy/tls terminator.";
|
|
|
|
};
|
2024-08-24 20:05:36 +00:00
|
|
|
global.database_path = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2021-09-02 09:55:51 +00:00
|
|
|
default = "/var/lib/matrix-conduit/";
|
|
|
|
readOnly = true;
|
|
|
|
description = ''
|
|
|
|
Path to the conduit database, the directory where conduit will save its data.
|
|
|
|
Note that due to using the DynamicUser feature of systemd, this value should not be changed
|
|
|
|
and is set to be read only.
|
|
|
|
'';
|
|
|
|
};
|
2024-08-24 20:05:36 +00:00
|
|
|
global.database_backend = lib.mkOption {
|
|
|
|
type = lib.types.enum [ "sqlite" "rocksdb" ];
|
2022-02-04 20:04:46 +00:00
|
|
|
default = "sqlite";
|
|
|
|
example = "rocksdb";
|
|
|
|
description = ''
|
|
|
|
The database backend for the service. Switching it on an existing
|
|
|
|
instance will require manual migration of data.
|
|
|
|
'';
|
|
|
|
};
|
2024-08-24 20:05:36 +00:00
|
|
|
global.allow_check_for_updates = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2023-08-11 06:16:19 +00:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to allow Conduit to automatically contact
|
|
|
|
<https://conduit.rs> hourly to check for important Conduit news.
|
|
|
|
|
|
|
|
Disabled by default because nixpkgs handles updates.
|
|
|
|
'';
|
|
|
|
};
|
2021-09-02 09:55:51 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
Generates the conduit.toml configuration file. Refer to
|
2024-04-24 07:11:03 +00:00
|
|
|
<https://docs.conduit.rs/configuration.html>
|
2021-09-02 09:55:51 +00:00
|
|
|
for details on supported values.
|
|
|
|
Note that database_path can not be edited because the service's reliance on systemd StateDir.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-08-24 20:05:36 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
2021-09-02 09:55:51 +00:00
|
|
|
systemd.services.conduit = {
|
|
|
|
description = "Conduit Matrix Server";
|
|
|
|
documentation = [ "https://gitlab.com/famedly/conduit/" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2024-11-04 12:08:03 +00:00
|
|
|
wants = [ "network-online.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
2021-09-02 09:55:51 +00:00
|
|
|
environment = lib.mkMerge ([
|
|
|
|
{ CONDUIT_CONFIG = configFile; }
|
|
|
|
cfg.extraEnvironment
|
|
|
|
]);
|
|
|
|
serviceConfig = {
|
|
|
|
DynamicUser = true;
|
|
|
|
User = "conduit";
|
|
|
|
LockPersonality = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateMounts = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallFilter = [
|
|
|
|
"@system-service"
|
|
|
|
"~@privileged"
|
|
|
|
];
|
|
|
|
StateDirectory = "matrix-conduit";
|
2023-07-25 14:54:39 +00:00
|
|
|
StateDirectoryMode = "0700";
|
2021-09-02 09:55:51 +00:00
|
|
|
ExecStart = "${cfg.package}/bin/conduit";
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = 10;
|
|
|
|
StartLimitBurst = 5;
|
2023-07-25 14:54:39 +00:00
|
|
|
UMask = "077";
|
2021-09-02 09:55:51 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|