|
|
|
@@ -6,47 +6,47 @@
|
|
|
|
|
}:
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
cfg = config.modules.services.matrix-synapse;
|
|
|
|
|
validBridges = [
|
|
|
|
|
"signal"
|
|
|
|
|
"whatsapp"
|
|
|
|
|
];
|
|
|
|
|
cfg = config.modules.services.matrix;
|
|
|
|
|
in {
|
|
|
|
|
options.modules.services.matrix-synapse = {
|
|
|
|
|
enable = lib.mkOption {
|
|
|
|
|
default = false;
|
|
|
|
|
example = true;
|
|
|
|
|
options.modules.services.matrix = {
|
|
|
|
|
enable = lib.mkEnableOption "matrix";
|
|
|
|
|
element = {
|
|
|
|
|
enable = lib.mkOption {
|
|
|
|
|
type = lib.types.bool;
|
|
|
|
|
default = true;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
enableElementWeb = lib.mkOption {
|
|
|
|
|
default = true;
|
|
|
|
|
example = false;
|
|
|
|
|
};
|
|
|
|
|
bridges = lib.mkOption {
|
|
|
|
|
type = lib.types.listOf lib.types.str;
|
|
|
|
|
description = "A list of bridges to configure with Synapse.";
|
|
|
|
|
example = [ "signal" "whatsapp" ];
|
|
|
|
|
default = [];
|
|
|
|
|
apply = bridges:
|
|
|
|
|
if lib.all (bridge: lib.elem bridge validBridges) bridges
|
|
|
|
|
then lib.map (b: "mautrix-${b}") bridges
|
|
|
|
|
else throw "Invalid bridge(s) specified. Valid bridges are: ${lib.concatStringsSep ", " validBridges}";
|
|
|
|
|
bridges = {
|
|
|
|
|
signal = lib.mkOption {
|
|
|
|
|
type = lib.types.bool;
|
|
|
|
|
default = false;
|
|
|
|
|
description = "Enable Signal bridge.";
|
|
|
|
|
};
|
|
|
|
|
whatsapp = lib.mkOption {
|
|
|
|
|
type = lib.types.bool;
|
|
|
|
|
default = false;
|
|
|
|
|
description = "Enable WhatsApp bridge.";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
serverName = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
|
|
|
|
default = "vimium.com";
|
|
|
|
|
example = "vimium.com";
|
|
|
|
|
};
|
|
|
|
|
usePostgresql = lib.mkOption {
|
|
|
|
|
default = false;
|
|
|
|
|
example = true;
|
|
|
|
|
};
|
|
|
|
|
usePostgresql = lib.mkEnableOption "postgresql";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = let
|
|
|
|
|
mkBridgeDatabase = bridge: {
|
|
|
|
|
name = bridge;
|
|
|
|
|
ensureDBOwnership = true;
|
|
|
|
|
matrixSubdomain = "matrix.${cfg.serverName}";
|
|
|
|
|
elementSubdomain = "chat.${cfg.serverName}";
|
|
|
|
|
matrixClientConfig = {
|
|
|
|
|
"m.homeserver" = {
|
|
|
|
|
base_url = "https://${matrixSubdomain}";
|
|
|
|
|
server_name = cfg.serverName;
|
|
|
|
|
};
|
|
|
|
|
"m.identity_server" = {};
|
|
|
|
|
};
|
|
|
|
|
matrixServerConfig."m.server" = "${matrixSubdomain}:443";
|
|
|
|
|
commonBridgeSettings = bridge: {
|
|
|
|
|
appservice = {
|
|
|
|
|
database = lib.mkIf cfg.usePostgresql {
|
|
|
|
@@ -62,42 +62,30 @@ in {
|
|
|
|
|
};
|
|
|
|
|
permissions = {
|
|
|
|
|
"${cfg.serverName}" = "user";
|
|
|
|
|
"@jordan:vimium.com" = "admin";
|
|
|
|
|
"@jordan:${cfg.serverName}" = "admin";
|
|
|
|
|
};
|
|
|
|
|
provisioning = {
|
|
|
|
|
shared_secret = "disable";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
homeserver = {
|
|
|
|
|
address = "https://matrix.${cfg.serverName}";
|
|
|
|
|
address = "https://${matrixSubdomain}";
|
|
|
|
|
domain = cfg.serverName;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
matrixClientConfig = {
|
|
|
|
|
"m.homeserver" = {
|
|
|
|
|
base_url = "https://matrix.${cfg.serverName}";
|
|
|
|
|
server_name = cfg.serverName;
|
|
|
|
|
};
|
|
|
|
|
"m.identity_server" = {};
|
|
|
|
|
};
|
|
|
|
|
matrixServerConfig."m.server" = "matrix.${cfg.serverName}:443";
|
|
|
|
|
mkWellKnown = data: ''
|
|
|
|
|
more_set_headers 'Content-Type: application/json';
|
|
|
|
|
return 200 '${builtins.toJSON data}';
|
|
|
|
|
'';
|
|
|
|
|
in lib.mkIf cfg.enable {
|
|
|
|
|
networking.firewall.allowedTCPPorts = [
|
|
|
|
|
8448 # Matrix federation
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
security.acme.certs = {
|
|
|
|
|
"matrix.${cfg.serverName}" = {
|
|
|
|
|
"${matrixSubdomain}" = {
|
|
|
|
|
reloadServices = [ "matrix-synapse" ];
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
services.nginx.virtualHosts = {
|
|
|
|
|
"matrix.${cfg.serverName}" = {
|
|
|
|
|
"${matrixSubdomain}" = {
|
|
|
|
|
forceSSL = true;
|
|
|
|
|
enableACME = true;
|
|
|
|
|
listen = [
|
|
|
|
@@ -147,12 +135,17 @@ in {
|
|
|
|
|
"/_synapse/client".proxyPass = "http://localhost:8008";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
"${cfg.serverName}" = {
|
|
|
|
|
"${cfg.serverName}" = let
|
|
|
|
|
mkWellKnown = data: ''
|
|
|
|
|
more_set_headers 'Content-Type: application/json';
|
|
|
|
|
return 200 '${builtins.toJSON data}';
|
|
|
|
|
'';
|
|
|
|
|
in {
|
|
|
|
|
locations."= /.well-known/matrix/server".extraConfig = (mkWellKnown matrixServerConfig);
|
|
|
|
|
locations."= /.well-known/matrix/client".extraConfig = (mkWellKnown matrixClientConfig);
|
|
|
|
|
};
|
|
|
|
|
} // (if cfg.enableElementWeb then {
|
|
|
|
|
"chat.${cfg.serverName}" = {
|
|
|
|
|
} // (if cfg.element.enable then {
|
|
|
|
|
"${elementSubdomain}" = {
|
|
|
|
|
forceSSL = true;
|
|
|
|
|
enableACME = true;
|
|
|
|
|
root = pkgs.unstable.element-web.override {
|
|
|
|
@@ -180,12 +173,12 @@ in {
|
|
|
|
|
max_upload_size = "100M";
|
|
|
|
|
report_stats = false;
|
|
|
|
|
server_name = cfg.serverName;
|
|
|
|
|
app_service_config_files = (lib.optional (lib.elem "mautrix-whatsapp" cfg.bridges)
|
|
|
|
|
app_service_config_files = (lib.optional cfg.bridges.whatsapp
|
|
|
|
|
"/var/lib/mautrix-whatsapp/whatsapp-registration.yaml");
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
systemd.services.matrix-synapse.serviceConfig.SupplementaryGroups =
|
|
|
|
|
(lib.optional (lib.elem "mautrix-whatsapp" cfg.bridges)
|
|
|
|
|
(lib.optional cfg.bridges.whatsapp
|
|
|
|
|
config.systemd.services.mautrix-whatsapp.serviceConfig.Group);
|
|
|
|
|
|
|
|
|
|
services.postgresql = lib.mkIf cfg.usePostgresql {
|
|
|
|
@@ -194,18 +187,30 @@ in {
|
|
|
|
|
name = "matrix-synapse";
|
|
|
|
|
ensureDBOwnership = true;
|
|
|
|
|
}
|
|
|
|
|
] ++ lib.map mkBridgeDatabase cfg.bridges;
|
|
|
|
|
] ++ (lib.optional cfg.bridges.signal
|
|
|
|
|
{
|
|
|
|
|
name = "mautrix-signal";
|
|
|
|
|
ensureDBOwnership = true;
|
|
|
|
|
})
|
|
|
|
|
++ (lib.optional cfg.bridges.whatsapp
|
|
|
|
|
{
|
|
|
|
|
name = "mautrix-whatsapp";
|
|
|
|
|
ensureDBOwnership = true;
|
|
|
|
|
});
|
|
|
|
|
ensureDatabases = [
|
|
|
|
|
"matrix-synapse"
|
|
|
|
|
] ++ cfg.bridges;
|
|
|
|
|
] ++ (lib.optional cfg.bridges.signal
|
|
|
|
|
"mautrix-signal")
|
|
|
|
|
++ (lib.optional cfg.bridges.whatsapp
|
|
|
|
|
"mautrix-whatsapp");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
services.mautrix-signal = lib.mkIf (lib.elem "mautrix-signal" cfg.bridges) {
|
|
|
|
|
services.mautrix-signal = lib.mkIf cfg.bridges.signal {
|
|
|
|
|
enable = true;
|
|
|
|
|
settings = commonBridgeSettings "mautrix-signal";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
services.mautrix-whatsapp = lib.mkIf (lib.elem "mautrix-whatsapp" cfg.bridges) {
|
|
|
|
|
services.mautrix-whatsapp = lib.mkIf cfg.bridges.whatsapp {
|
|
|
|
|
enable = true;
|
|
|
|
|
settings = {
|
|
|
|
|
bridge = {
|