helm/profiles/matrix/default.nix

367 lines
10 KiB
Nix
Raw Normal View History

2022-07-01 07:21:51 -07:00
{ config, lib, pkgs, ... }:
2021-11-13 09:47:38 -08:00
{
security.acme.email = "anish+acme@lakhwara.com";
security.acme.acceptTerms = true;
services.matrix-synapse = {
enable = true;
app_service_config_files = [
2022-07-01 07:21:51 -07:00
# # The registration file is automatically generated after starting the appservice for the first time.
# # cp /var/lib/matrix-appservice-discord/discord-registration.yaml /var/lib/matrix-synapse/
# # chown matrix-synapse:matrix-synapse /var/lib/matrix-synapse/discord-registration.yaml
"/var/lib/matrix-synapse/discord-registration.yaml"
"/var/lib/matrix-synapse/telegram-registration.yaml"
#"/var/lib/matrix-synapse/slack-registration.yaml"
#"/var/lib/matrix-synapse/whatsapp-registration.yaml"
2021-11-13 09:47:38 -08:00
];
server_name = "sealight.xyz";
2022-07-01 07:21:51 -07:00
registration_shared_secret = "hD9HQGTTDxp0mQsQ5JDsfudWMDiubmZENOgPchIvfBvUlPxlvQSvjoO4wn2L1seU";
2021-11-13 09:47:38 -08:00
enable_metrics = true;
enable_registration = true;
database_type = "psycopg2";
database_args = {
database = "matrix-synapse";
};
listeners = [
{
port = 8448;
tls = false;
resources = [{
2022-07-01 07:21:51 -07:00
compress = true;
names = [ "client" "federation" ];
}];
2021-11-13 09:47:38 -08:00
}
{
port = 9090;
type = "metrics";
bind_address = "0.0.0.0";
2022-07-01 07:21:51 -07:00
resources = [{
2021-11-13 09:47:38 -08:00
compress = false;
2022-07-01 07:21:51 -07:00
names = [ ];
2021-11-13 09:47:38 -08:00
}];
tls = false;
}
];
2022-07-01 07:21:51 -07:00
extraConfig = ''
max_upload_size: "50M"
use_presence: false
'';
## coturn based TURN server integration (TURN server setup mentioned later),
## shared secret generated while configuring coturn
## and reused here (power of Nix being a real programming language)
turn_uris = [
"turn:turn.sealight.xyz:3478?transport=udp"
"turn:turn.sealight.xyz:3478?transport=tcp"
];
turn_shared_secret = config.services.coturn.static-auth-secret;
2021-11-13 09:47:38 -08:00
};
services.coturn = {
enable = true;
use-auth-secret = true;
static-auth-secret = "jXW1ohIq6wM3NB00xeME3uBihY85xjpkhGoyzBIdwhOpj7gjyxXZu1fwp1lUiYwJ";
realm = "turn.sealight.xyz";
2022-07-01 07:21:51 -07:00
min-port = 49111;
max-port = 51111;
no-cli = true;
2021-11-13 09:47:38 -08:00
no-tcp-relay = true;
no-tls = true;
2022-07-01 07:21:51 -07:00
cert = "${config.security.acme.certs."turn.sealight.xyz".directory}/full.pem";
pkey = "${config.security.acme.certs."turn.sealight.xyz".directory}/key.pem";
2021-11-13 09:47:38 -08:00
extraConfig = ''
2022-07-01 07:21:51 -07:00
verbose
user-quota=12
total-quota=1200
denied-peer-ip=10.0.0.0-10.255.255.255
denied-peer-ip=192.168.0.0-192.168.255.255
denied-peer-ip=172.16.0.0-172.31.255.255
denied-peer-ip=0.0.0.0-0.255.255.255
denied-peer-ip=100.64.0.0-100.127.255.255
denied-peer-ip=127.0.0.0-127.255.255.255
denied-peer-ip=169.254.0.0-169.254.255.255
denied-peer-ip=192.0.0.0-192.0.0.255
denied-peer-ip=192.0.2.0-192.0.2.255
denied-peer-ip=192.88.99.0-192.88.99.255
denied-peer-ip=198.18.0.0-198.19.255.255
denied-peer-ip=198.51.100.0-198.51.100.255
denied-peer-ip=203.0.113.0-203.0.113.255
denied-peer-ip=240.0.0.0-255.255.255.255
2021-11-13 09:47:38 -08:00
'';
};
2022-07-01 07:21:51 -07:00
security.acme.certs.${config.services.coturn.realm} = {
/* insert here the right configuration to obtain a certificate */
webroot = "/var/lib/acme/acme-challenge/";
email = "anish+acme@lakhwara.com";
postRun = "systemctl restart coturn.service";
group = "turnserver";
};
2021-11-13 09:47:38 -08:00
services.jitsi-meet = {
enable = true;
hostName = "jitsi.sealight.xyz";
};
services.jitsi-videobridge.enable = true;
services.mautrix-telegram = {
enable = true;
environmentFile = /etc/secrets/telegram.env; # file containing the appservice and telegram tokens
# The appservice is pre-configured to use SQLite by default. It's also possible to use PostgreSQL.
settings = {
homeserver = {
2022-07-01 07:21:51 -07:00
address = "https://sealight.xyz";
2021-11-13 09:47:38 -08:00
domain = "sealight.xyz";
};
appservice = {
provisioning.enabled = false;
id = "telegram";
2022-07-01 07:21:51 -07:00
bot_username = "telegrambridge";
2021-11-13 09:47:38 -08:00
public = {
enabled = false;
prefix = "/public";
external = "https://chat.sealight.xyz/public";
};
2022-07-01 07:21:51 -07:00
address = "http://localhost:18787";
port = 18787;
2021-11-13 09:47:38 -08:00
# The service uses SQLite by default, but it's also possible to use PostgreSQL instead:
#database = "postgresql:///mautrix-telegram?host=/run/postgresql";
};
bridge = {
relaybot.authless_portals = false;
permissions = {
"@aynish:sealight.xyz" = "admin";
};
};
};
};
2022-07-01 07:21:51 -07:00
services.mx-puppet-discord = {
2021-11-13 09:47:38 -08:00
enable = true;
2022-07-01 07:21:51 -07:00
settings = {
bridge = {
bindAddress = "localhost";
port = 16785;
2021-11-13 09:47:38 -08:00
domain = "sealight.xyz";
2022-07-01 07:21:51 -07:00
homeserverUrl = "https://sealight.xyz";
avatarUrl = "https://discord.com/assets/2d20a45d79110dc5bf947137e9d99b66.svg";
2021-11-13 09:47:38 -08:00
};
2022-07-01 07:21:51 -07:00
provisioning = {
whitelist = [ "@aynish:sealight.xyz" ];
2021-11-13 09:47:38 -08:00
};
2022-07-01 07:21:51 -07:00
relay = {
whitelist = [ "@aynish:sealight.xyz" ];
2021-11-13 09:47:38 -08:00
};
2022-07-01 07:21:51 -07:00
namePatterns = {
group = ":name";
room = ":name";
user = ":name (Discord)";
userOverride = ":displayname";
2021-11-13 09:47:38 -08:00
};
2022-07-01 07:21:51 -07:00
presence = {
enabled = false;
2021-11-13 09:47:38 -08:00
};
};
2022-07-01 07:21:51 -07:00
serviceDependencies = [ "matrix-synapse.service" ];
2021-11-13 09:47:38 -08:00
};
2022-07-01 07:21:51 -07:00
services.heisenbridge = {
2021-11-13 09:47:38 -08:00
enable = true;
2022-07-01 07:21:51 -07:00
homeserver = "https://sealight.xyz";
listenPort = 14456;
appServiceToken = "wyujLh8kjpmk2bfKeEE3sZ2gWOEUBKK5";
homeserverToken = "yEHs7lthD2ZHUibJOAv1APaFhEjxN5PT";
2021-11-13 09:47:38 -08:00
};
services.postgresql = {
enable = true;
## postgresql user and db name remains in the
## service.matrix-synapse.database_args setting which
## by default is matrix-synapse
initialScript = pkgs.writeText "synapse-init.sql" ''
2022-07-01 07:21:51 -07:00
CREATE ROLE "matrix-synapse" WITH LOGIN PASSWORD "Da0?H*9i{x?,]|'kq@iBwlIzu";
CREATE DATABASE "matrix-synapse" WITH OWNER "matrix-synapse"
TEMPLATE template0
LC_COLLATE = "C"
LC_CTYPE = "C";
'';
2021-11-13 09:47:38 -08:00
};
2022-07-01 07:21:51 -07:00
networking.firewall =
let
range = with config.services.coturn; [{
from = min-port;
to = max-port;
}];
in
{
enable = true;
allowedUDPPortRanges = range; # coturn
allowedTCPPortRanges = range;
allowedTCPPorts = [
22 # SSH
8448 # Matrix federation
8008
80
443
3478 # Coturn service
5349 # Coturn service
9090 # Synapse Metrics
];
allowedUDPPorts = [
3478
5349 # Coturn service
];
};
2021-11-13 09:47:38 -08:00
2022-07-01 07:21:51 -07:00
nixpkgs.overlays = [
2021-11-13 09:47:38 -08:00
(self: super: {
2022-07-01 07:21:51 -07:00
element-web = super.element-web.override {
conf = {
default_server_config = {
"m.homeserver" = {
"base_url" = "https://chat.sealight.xyz";
"server_name" = "sealight.xyz";
};
"m.identity_server" = {
"base_url" = "https://vector.im";
2021-11-13 09:47:38 -08:00
};
2022-07-01 07:21:51 -07:00
};
## jitsi will be setup later,
## but we need to add to Riot configuration
jitsi.preferredDomain = "jitsi.sealight.xyz";
2021-11-13 09:47:38 -08:00
};
2022-07-01 07:21:51 -07:00
};
2021-11-13 09:47:38 -08:00
})
];
services.nginx = {
2022-07-01 07:21:51 -07:00
enable = true;
virtualHosts = {
"sealight.xyz" = {
#forceSSL = true;
#enableACME = true;
2022-07-01 07:21:51 -07:00
locations."/" = {
root = "/var/www/sealight.xyz";
};
locations."/_matrix" = {
proxyPass = "http://localhost:8448";
};
locations."/slackbridge" = {
proxyPass = "http://localhost:9899";
};
};
## virtual host for Synapse
"chat.sealight.xyz" = {
#forceSSL = true;
#enableACME = true;
2022-07-01 07:21:51 -07:00
#useACMEHost = "sealight.xyz";
locations."/" = {
proxyPass = "http://localhost:8448";
};
};
## virtual host for Riot/Web
"element.sealight.xyz" = {
#forceSSL = true;
#enableACME = true;
2022-07-01 07:21:51 -07:00
#useACMEHost = "sealight.xyz";
## root points to the riot-web package content, also configured via Nix
locations."/" = {
root = pkgs.element-web;
};
};
${config.services.jitsi-meet.hostName} = {
#enableACME = true;
#forceSSL = true;
2022-07-01 07:21:51 -07:00
};
};
## other nginx specific best practices
recommendedGzipSettings = true;
recommendedOptimisation = true;
recommendedTlsSettings = true;
};
2021-11-13 09:47:38 -08:00
2022-07-01 07:21:51 -07:00
# environment.systemPackages = with pkgs; [ matrix-appservice-slack ];
#services.mx-puppet-slack= {
#enable = false;
#settings = {
# bridge = {
# bindAddress = "localhost";
# port = 16786;
# domain = "sealight.xyz";
# homeserverUrl = "https://sealight.xyz";
# };
# provisioning = {
# whitelist = [ "@aynish:sealight.xyz" ];
# };
# relay = {
# whitelist = [ "@aynish:sealight.xyz" ];
# };
# namePatterns = {
# group = ":name";
# room = ":name[:team? - :team,]";
# user = ":name (Slack)";
# userOverride = ":displayname";
# };
# presence = {
# enabled = false;
# };
# oauth = {
# enabled = false;
# };
#};
#serviceDependencies = ["matrix-synapse.service"];
#};
2021-11-13 09:47:38 -08:00
2022-07-01 07:21:51 -07:00
# services.mautrix-whatsapp = {
# enable = false;
# The appservice is pre-configured to use SQLite by default. It's also possible to use PostgreSQL.
#configOptions = {
# homeserver = {
# address = "https://chat.sealight.xyz";
# domain = "sealight.xyz";
# };
# appservice = {
# id = "whatsapp";
# address = http://localhost:9897;
# hostname = "0.0.0.0";
# port = 9897;
# database = {
# type = "sqlite3";
# uri = "/var/lib/mautrix-whatsapp/mautrix-whatsapp.db";
# };
# state_store_path = "/var/lib/mautrix-whatsapp/mx-state.json";
# bot = {
# username = "whatsappbot";
# displayname = "WhatsApp bridge bot";
# avatar = "mxc://maunium.net/NeXNQarUbrlYBiPCpprYsRqr";
# };
# as_token = "";
# hs_token = "";
# };
# bridge = {
# username_template = "whatsapp_{{.}}";
# displayname_template = "{{if .Notify}}{{.Notify}}{{else}}{{.Jid}}{{end}} (WA)";
# command_prefix = "!wa";
# permissions = {
# "@aynish:sealight.xyz" = 100;
# };
# };
# logging = {
# directory = "/var/lib/mautrix-whatsapp/logs";
# file_name_format = "{{.Date}}-{{.Index}}.log";
# file_date_format = "\"2006-01-02\"";
# file_mode = 384;
# timestamp_format = "Jan _2, 2006 15:04:05";
# print_level = "debug";
# };
# metrics = {
# enabled = true;
# listen = "http://localhost:5070";
# };
#};
# };
2021-11-13 09:47:38 -08:00
}