zion/modules/communication.nix

147 lines
4.2 KiB
Nix
Raw Normal View History

2020-12-28 18:42:26 +01:00
{ config, lib, pkgs, ... }:
2022-07-20 16:34:14 +02:00
with pkgs;
# NOTE Reference the environment variable set in the corresponding agenix secret
2022-10-23 17:34:55 +02:00
let
database = {
connection_string = "$DB_STRING";
max_open_conns = 100;
max_idle_conns = 5;
conn_max_lifetime = -1;
};
2022-07-20 16:34:14 +02:00
in {
2020-12-28 18:42:26 +01:00
# Matrix server configuration
2022-07-20 16:34:14 +02:00
services.dendrite = {
2020-12-28 18:42:26 +01:00
enable = true;
2022-07-20 16:34:14 +02:00
httpPort = 8008;
environmentFile = config.age.secrets.dendrite-postgres.path;
loadCredential = [ "private_key:${config.age.secrets.dendrite.path}" ];
settings = {
2022-07-20 16:34:14 +02:00
global = {
server_name = "coolneng.duckdns.org";
private_key = config.age.secrets.dendrite.path;
inherit database;
2022-10-23 17:34:55 +02:00
dns_cache.enabled = true;
2022-07-20 16:34:14 +02:00
};
# HACK Inherit postgres connection string for the rest of the DBs
app_service_api = { inherit database; };
2022-07-20 16:34:14 +02:00
media_api = { inherit database; };
room_server = { inherit database; };
push_server = { inherit database; };
mscs = {
inherit database;
mscs = [ "msc2836" "msc2946" ];
};
sync_api = { inherit database; };
key_server = { inherit database; };
federation_api = { inherit database; };
user_api = {
account_database = database;
device_database = database;
};
};
2020-12-28 18:42:26 +01:00
};
# Start dendrite after config files are mounted
systemd.services.dendrite.unitConfig.RequiresMountsFor = [
/var/lib/matrix-as-facebook
/var/lib/matrix-as-signal
/var/lib/matrix-as-telegram
];
2022-07-20 16:34:14 +02:00
# Matrix bridges
services.matrix-appservices = {
homeserver = "dendrite";
2022-07-20 19:18:10 +02:00
homeserverDomain = "coolneng.duckdns.org";
homeserverURL = "https://matrix.coolneng.duckdns.org";
2022-07-20 16:34:14 +02:00
addRegistrationFiles = true;
services = {
telegram = {
2021-02-03 18:38:41 +01:00
port = 8118;
2022-07-20 16:34:14 +02:00
format = "mautrix-python";
package = mautrix-telegram;
2022-07-20 22:38:20 +02:00
serviceConfig.EnvironmentFile = config.age.secrets.telegram.path;
2022-07-22 17:14:00 +02:00
settings = {
appservice.database = "$DB_STRING";
homeserver.software = "standard";
2022-07-22 17:14:00 +02:00
telegram = {
api_id = "$API_ID";
api_hash = "$API_HASH";
};
bridge = {
permissions."@coolneng:coolneng.duckdns.org" = "admin";
backfill.normal_groups = true;
};
2022-07-20 22:38:20 +02:00
};
2022-07-20 16:34:14 +02:00
};
facebook = {
port = 8228;
format = "mautrix-python";
package = mautrix-facebook;
serviceConfig.EnvironmentFile = config.age.secrets.facebook.path;
settings = {
appservice.database = "$DB_STRING";
homeserver.software = "standard";
2023-07-15 18:24:56 +02:00
bridge.permissions."@coolneng:coolneng.duckdns.org" = "admin";
};
2022-07-20 16:34:14 +02:00
};
signal = {
port = 8338;
format = "mautrix-python";
2023-06-08 18:30:16 +02:00
package = mautrix-signal;
2022-07-20 16:34:14 +02:00
serviceConfig = {
EnvironmentFile = config.age.secrets.signal.path;
2022-07-20 16:34:14 +02:00
StateDirectory = [ "matrix-as-signal" "signald" ];
JoinNamespaceOf = "signald.service";
SupplementaryGroups = [ "signald" ];
};
settings = {
appservice.database = "$DB_STRING";
homeserver.software = "standard";
2023-07-15 18:24:56 +02:00
bridge.permissions."@coolneng:coolneng.duckdns.org" = "admin";
signal = {
socket_path = config.services.signald.socketPath;
outgoing_attachment_dir = "/var/lib/signald/tmp";
};
2022-07-20 16:34:14 +02:00
};
2020-12-28 18:42:26 +01:00
};
};
};
2022-07-20 16:34:14 +02:00
# Additional settings for mautrix-signal
2022-07-20 22:37:52 +02:00
services.signald = {
enable = true;
user = "matrix-as-signal";
};
2022-07-20 16:34:14 +02:00
systemd.services.matrix-as-signal = {
requires = [ "signald.service" ];
after = [ "signald.service" ];
unitConfig.JoinsNamespaceOf = "signald.service";
2022-08-29 21:41:53 +02:00
path = [ ffmpeg ];
2022-07-20 16:34:14 +02:00
};
# Enable voice messages for facebook
systemd.services.matrix-as-facebook.path = [ ffmpeg ];
2023-04-03 00:50:47 +02:00
# MQTT configuration
services.mosquitto = {
enable = true;
dataDir = "/vault/mosquitto";
logType = [ "websockets" "error" "warning" "notice" "information" ];
logDest = [ "syslog" ];
listeners = [{
users.homeostasis = {
acl = [ "write #" ];
hashedPasswordFile = config.age.secrets.mqtt-sender.path;
};
users.prometheus = {
acl = [ "read #" ];
hashedPasswordFile = config.age.secrets.mqtt-receiver.path;
};
}];
};
2020-12-28 18:42:26 +01:00
}