2024-02-08 23:21:10 +03:00
|
|
|
{ config, lib, inputs, ... }:
|
2024-01-18 21:46:51 +03:00
|
|
|
let
|
2024-03-04 00:00:27 +03:00
|
|
|
external-ip = "91.202.204.123";
|
2024-01-18 21:46:51 +03:00
|
|
|
coturn-denied-ips = [
|
|
|
|
"0.0.0.0-0.255.255.255"
|
|
|
|
"10.0.0.0-10.255.255.255"
|
|
|
|
"100.64.0.0-100.127.255.255"
|
|
|
|
"127.0.0.0-127.255.255.255"
|
|
|
|
"169.254.0.0-169.254.255.255"
|
|
|
|
"172.16.0.0-172.31.255.255"
|
|
|
|
"192.0.0.0-192.0.0.255"
|
|
|
|
"192.0.2.0-192.0.2.255"
|
|
|
|
"192.88.99.0-192.88.99.255"
|
|
|
|
"192.168.0.0-192.168.255.255"
|
|
|
|
"198.18.0.0-198.19.255.255"
|
|
|
|
"198.51.100.0-198.51.100.255"
|
|
|
|
"203.0.113.0-203.0.113.255"
|
|
|
|
"240.0.0.0-255.255.255.255"
|
|
|
|
"::1"
|
|
|
|
"64:ff9b::-64:ff9b::ffff:ffff"
|
|
|
|
"::ffff:0.0.0.0-::ffff:255.255.255.255"
|
|
|
|
"100::-100::ffff:ffff:ffff:ffff"
|
|
|
|
"2001::-2001:1ff:ffff:ffff:ffff:ffff:ffff:ffff"
|
|
|
|
"2002::-2002:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
|
|
|
|
"fc00::-fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
|
|
|
|
"fe80::-febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
|
|
|
|
];
|
2024-03-04 00:00:27 +03:00
|
|
|
cert-fqdn = "ataraxiadev.com";
|
2024-01-18 21:46:51 +03:00
|
|
|
in {
|
|
|
|
sops.secrets.auth-secret = {
|
2024-03-04 00:00:27 +03:00
|
|
|
sopsFile = inputs.self.secretsDir + /home-hypervisor/coturn.yaml;
|
2024-01-18 21:46:51 +03:00
|
|
|
restartUnits = [ "coturn.service" ];
|
|
|
|
owner = config.users.users.turnserver.name;
|
|
|
|
mode = "0400";
|
|
|
|
};
|
|
|
|
|
|
|
|
virtualisation.libvirt.guests.debian-matrix = {
|
|
|
|
autoStart = true;
|
|
|
|
user = config.mainuser;
|
|
|
|
group = "libvirtd";
|
2024-03-04 00:00:27 +03:00
|
|
|
xmlFile = ./vm.xml;
|
2024-01-18 21:46:51 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
services.coturn = {
|
|
|
|
enable = true;
|
|
|
|
use-auth-secret = true;
|
|
|
|
static-auth-secret-file = config.sops.secrets.auth-secret.path;
|
|
|
|
realm = "turn.ataraxiadev.com";
|
|
|
|
min-port = 49152;
|
|
|
|
max-port = 49262;
|
|
|
|
no-cli = true;
|
|
|
|
cert = "${config.security.acme.certs.${cert-fqdn}.directory}/fullchain.pem";
|
|
|
|
pkey = "${config.security.acme.certs.${cert-fqdn}.directory}/key.pem";
|
|
|
|
no-tcp-relay = true;
|
|
|
|
extraConfig = ''
|
|
|
|
external-ip=${external-ip}
|
|
|
|
userdb=/var/lib/coturn/turnserver.db
|
|
|
|
no-tlsv1
|
|
|
|
no-tlsv1_1
|
|
|
|
no-rfc5780
|
|
|
|
no-stun-backward-compatibility
|
|
|
|
response-origin-only-with-rfc5780
|
|
|
|
no-multicast-peers
|
|
|
|
'' + lib.strings.concatMapStringsSep "\n" (x: "denied-peer-ip=${x}")
|
|
|
|
coturn-denied-ips;
|
|
|
|
};
|
|
|
|
systemd.services.coturn.serviceConfig.StateDirectory = "coturn";
|
|
|
|
systemd.services.coturn.serviceConfig.Group = lib.mkForce "acme";
|
|
|
|
|
|
|
|
networking = let
|
|
|
|
libvirt-ifname = "virbr0";
|
|
|
|
guest-ip = "192.168.122.11";
|
|
|
|
synapse-ports = [ 8081 8448 8766 ];
|
|
|
|
turn-ports = with config.services.coturn; [
|
|
|
|
listening-port tls-listening-port
|
|
|
|
alt-listening-port alt-tls-listening-port
|
|
|
|
];
|
|
|
|
in {
|
|
|
|
firewall = {
|
|
|
|
allowedUDPPortRanges = with config.services.coturn; [{
|
|
|
|
from = min-port;
|
|
|
|
to = max-port;
|
|
|
|
}];
|
|
|
|
allowedUDPPorts = turn-ports;
|
|
|
|
allowedTCPPorts = turn-ports ++ synapse-ports;
|
|
|
|
};
|
|
|
|
nat = {
|
|
|
|
enable = true;
|
2024-03-04 00:00:27 +03:00
|
|
|
internalInterfaces = [ "br0" ];
|
2024-01-18 21:46:51 +03:00
|
|
|
externalInterface = libvirt-ifname;
|
|
|
|
forwardPorts = [{
|
|
|
|
sourcePort = 8081;
|
|
|
|
proto = "tcp";
|
|
|
|
destination = "${guest-ip}:8081";
|
|
|
|
} {
|
|
|
|
sourcePort = 8448;
|
|
|
|
proto = "tcp";
|
|
|
|
destination = "${guest-ip}:8448";
|
|
|
|
} {
|
|
|
|
sourcePort = 8766;
|
|
|
|
proto = "tcp";
|
|
|
|
destination = "${guest-ip}:8766";
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
};
|
2024-03-04 00:00:27 +03:00
|
|
|
|
|
|
|
services.nginx.virtualHosts = let
|
|
|
|
proxySettings = ''
|
2024-04-23 21:37:21 +03:00
|
|
|
client_max_body_size 50M;
|
2024-03-04 00:00:27 +03:00
|
|
|
proxy_set_header Host $host;
|
2024-04-23 21:37:21 +03:00
|
|
|
proxy_set_header X-Forwarded-For $remote_addr;
|
2024-03-04 00:00:27 +03:00
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
'';
|
|
|
|
default = {
|
|
|
|
useACMEHost = cert-fqdn;
|
|
|
|
enableACME = false;
|
|
|
|
forceSSL = true;
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
"matrix:443" = {
|
|
|
|
serverAliases = [
|
|
|
|
"matrix.ataraxiadev.com"
|
|
|
|
"element.ataraxiadev.com"
|
|
|
|
];
|
|
|
|
listen = [{
|
|
|
|
addr = "0.0.0.0";
|
|
|
|
port = 443;
|
|
|
|
ssl = true;
|
2024-04-23 21:37:21 +03:00
|
|
|
} {
|
|
|
|
addr = "[::]";
|
|
|
|
port = 443;
|
|
|
|
ssl = true;
|
2024-03-04 00:00:27 +03:00
|
|
|
}];
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://192.168.122.11:8081";
|
|
|
|
extraConfig = ''
|
2024-04-23 21:37:21 +03:00
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
2024-03-04 00:00:27 +03:00
|
|
|
'' + proxySettings;
|
|
|
|
};
|
|
|
|
} // default;
|
|
|
|
"matrix:8448" = {
|
|
|
|
serverAliases = [ "matrix.ataraxiadev.com" ];
|
|
|
|
listen = [{
|
|
|
|
addr = "0.0.0.0";
|
|
|
|
port = 8448;
|
|
|
|
ssl = true;
|
2024-04-23 21:37:21 +03:00
|
|
|
} {
|
|
|
|
addr = "[::]";
|
|
|
|
port = 8448;
|
|
|
|
ssl = true;
|
2024-03-04 00:00:27 +03:00
|
|
|
}];
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://192.168.122.11:8448";
|
2024-04-23 21:37:21 +03:00
|
|
|
extraConfig = proxySettings;
|
2024-03-04 00:00:27 +03:00
|
|
|
};
|
|
|
|
} // default;
|
|
|
|
};
|
2024-01-18 21:46:51 +03:00
|
|
|
}
|