2026-02-17 18:24:34 -05:00
|
|
|
{
|
|
|
|
|
pkgs,
|
|
|
|
|
userName,
|
|
|
|
|
...
|
2026-02-24 00:42:55 -05:00
|
|
|
}: let
|
|
|
|
|
# INFO: set these to your liking
|
|
|
|
|
matrixFqdn = "chat.wyattjmiller.com";
|
|
|
|
|
rtcFqdn = "rtc.wyattjmiller.com";
|
|
|
|
|
|
|
|
|
|
supportEmail = "wyatt@wyattjmiller.com";
|
2026-02-23 21:53:20 -05:00
|
|
|
livekitKeyFile = "/var/lib/livekit/livekit.key";
|
|
|
|
|
matrixRegistrationTokenFile = "/var/lib/matrix.key";
|
|
|
|
|
in {
|
2026-02-17 18:24:34 -05:00
|
|
|
imports = [
|
|
|
|
|
../../pwrMgmt
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
# Enable flakes for NixOS
|
|
|
|
|
nix.settings.experimental-features = ["nix-command" "flakes"];
|
|
|
|
|
|
2026-02-23 21:53:20 -05:00
|
|
|
nix.settings = {
|
|
|
|
|
download-buffer-size = 134217728; # 128 MiB in bytes
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-17 18:24:34 -05:00
|
|
|
# Custom kernel/boot stuff
|
|
|
|
|
boot.kernelPackages = pkgs.linuxPackages_latest;
|
|
|
|
|
|
|
|
|
|
# Set your timezone
|
|
|
|
|
time.timeZone = "America/Detroit";
|
|
|
|
|
|
|
|
|
|
# Enable OpenSSH
|
2026-02-18 19:55:43 -05:00
|
|
|
services.openssh = {
|
|
|
|
|
enable = true;
|
2026-02-23 21:53:20 -05:00
|
|
|
settings.PermitRootLogin = "no";
|
|
|
|
|
settings.PasswordAuthentication = false;
|
2026-02-18 19:55:43 -05:00
|
|
|
};
|
2026-02-17 18:24:34 -05:00
|
|
|
|
|
|
|
|
# Enable keyring
|
|
|
|
|
services.gnome.gnome-keyring.enable = true;
|
|
|
|
|
|
|
|
|
|
# Enable GnuPG
|
|
|
|
|
programs.gnupg.agent = {
|
|
|
|
|
enable = true;
|
|
|
|
|
enableSSHSupport = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# Enable SUID wrappers (some programs need them)
|
|
|
|
|
programs.mtr.enable = true;
|
|
|
|
|
|
|
|
|
|
# Enable Polkit
|
|
|
|
|
security.polkit.enable = true;
|
|
|
|
|
|
|
|
|
|
# Power management (see ../../pwrMgmt/default.nix)
|
|
|
|
|
pwrMgmt = {
|
|
|
|
|
enable = true;
|
|
|
|
|
cpuFreqGovernor = "performance";
|
|
|
|
|
powertop.enable = false;
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-18 14:57:21 -05:00
|
|
|
# Firewall settings (fallback, upstream way of doing things)
|
|
|
|
|
networking.firewall = {
|
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
|
|
allowedTCPPorts = [
|
2026-02-23 21:53:20 -05:00
|
|
|
80
|
|
|
|
|
443
|
|
|
|
|
8448
|
2026-02-18 14:57:21 -05:00
|
|
|
3478
|
|
|
|
|
5349
|
|
|
|
|
7880
|
|
|
|
|
7881
|
|
|
|
|
8080
|
2026-02-23 21:53:20 -05:00
|
|
|
8081
|
2026-02-18 14:57:21 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
allowedUDPPorts = [
|
|
|
|
|
3478
|
2026-02-24 00:08:30 -05:00
|
|
|
7881
|
2026-02-23 21:53:20 -05:00
|
|
|
8448
|
2026-02-18 14:57:21 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
allowedUDPPortRanges =[
|
2026-02-23 21:53:20 -05:00
|
|
|
# TURN UDP relays
|
|
|
|
|
{
|
2026-02-18 14:57:21 -05:00
|
|
|
from = 49000;
|
|
|
|
|
to = 50000;
|
|
|
|
|
}
|
2026-02-23 21:53:20 -05:00
|
|
|
#
|
2026-02-18 14:57:21 -05:00
|
|
|
{
|
|
|
|
|
from = 50100;
|
|
|
|
|
to = 50200;
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-17 18:24:34 -05:00
|
|
|
# Add username to groups "wheel" and "video" - more may be added here later
|
2026-02-18 19:55:43 -05:00
|
|
|
users.users.${userName} = {
|
|
|
|
|
openssh.authorizedKeys.keys = [
|
|
|
|
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFV9eSc9L+aJLoKoexq2f/jb5rpyZnhuGiyhS8YQAbaS wyatt@wyattjmiller.com"
|
|
|
|
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO4WKvKnnYpTbzZHFEslOKyfiiMqWxhW3AfX6E7ACmYU wyatt@wyattjmiller.com"
|
|
|
|
|
];
|
|
|
|
|
extraGroups = ["wheel" "video" "network"];
|
|
|
|
|
};
|
2026-02-17 18:24:34 -05:00
|
|
|
|
|
|
|
|
# fail2ban
|
|
|
|
|
services.fail2ban = {
|
2026-02-18 08:40:47 -05:00
|
|
|
enable = true;
|
|
|
|
|
package = pkgs.fail2ban;
|
|
|
|
|
maxretry = 5;
|
|
|
|
|
bantime = "3h";
|
|
|
|
|
bantime-increment = {
|
|
|
|
|
enable = true;
|
|
|
|
|
rndtime = "10m";
|
|
|
|
|
};
|
2026-02-17 18:24:34 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# Matrix server
|
|
|
|
|
services.matrix-tuwunel = {
|
2026-02-18 08:40:47 -05:00
|
|
|
enable = true;
|
|
|
|
|
package = pkgs.matrix-tuwunel;
|
|
|
|
|
settings = {
|
|
|
|
|
global = {
|
2026-02-24 00:42:55 -05:00
|
|
|
server_name = matrixFqdn;
|
2026-02-18 08:40:47 -05:00
|
|
|
allow_encryption = true;
|
|
|
|
|
allow_federation = true;
|
2026-02-23 21:53:20 -05:00
|
|
|
allow_registration = true;
|
|
|
|
|
registration_token = matrixRegistrationTokenFile;
|
2026-02-18 14:57:21 -05:00
|
|
|
allow_unstable_room_versions = false;
|
|
|
|
|
allow_experimental_room_versions = false;
|
|
|
|
|
zstd_compression = true;
|
|
|
|
|
new_user_displayname_suffix = "✨";
|
|
|
|
|
max_request_size = 1048575600; # 100MB in bytes, for file uploads
|
2026-02-18 19:55:43 -05:00
|
|
|
database_backup_path = "/var/lib/tuwunel/database_backups";
|
|
|
|
|
database_backups_to_keep = 2;
|
2026-02-18 14:57:21 -05:00
|
|
|
|
|
|
|
|
address = [
|
|
|
|
|
"127.0.0.1"
|
|
|
|
|
"::1"
|
|
|
|
|
];
|
|
|
|
|
port = [ 8008 ];
|
|
|
|
|
|
|
|
|
|
well_known = {
|
2026-02-24 00:42:55 -05:00
|
|
|
client = "https://${matrixFqdn}";
|
|
|
|
|
server = "${matrixFqdn}:443";
|
|
|
|
|
support_email = supportEmail;
|
|
|
|
|
support_mxid = "@wymiller:${matrixFqdn}";
|
2026-02-18 14:57:21 -05:00
|
|
|
|
2026-02-23 21:53:20 -05:00
|
|
|
rtc_transports = [{
|
2026-02-18 14:57:21 -05:00
|
|
|
type = "livekit";
|
2026-02-24 00:42:55 -05:00
|
|
|
livekit_service_url = "https://${rtcFqdn}";
|
2026-02-23 21:53:20 -05:00
|
|
|
}];
|
2026-02-18 14:57:21 -05:00
|
|
|
};
|
2026-02-18 08:40:47 -05:00
|
|
|
};
|
|
|
|
|
};
|
2026-02-17 18:24:34 -05:00
|
|
|
};
|
|
|
|
|
|
2026-02-18 19:55:43 -05:00
|
|
|
# LiveKit (Matrix RTC)
|
2026-02-17 18:24:34 -05:00
|
|
|
services.livekit = {
|
2026-02-18 08:40:47 -05:00
|
|
|
enable = true;
|
|
|
|
|
package = pkgs.livekit;
|
|
|
|
|
openFirewall = true;
|
2026-02-23 21:53:20 -05:00
|
|
|
keyFile = livekitKeyFile;
|
2026-02-18 08:40:47 -05:00
|
|
|
settings = {
|
2026-02-18 14:57:21 -05:00
|
|
|
port = 7880;
|
|
|
|
|
room.auto_create = true;
|
|
|
|
|
rtc = {
|
|
|
|
|
use_external_ip = true;
|
|
|
|
|
};
|
2026-02-18 08:40:47 -05:00
|
|
|
};
|
2026-02-17 18:24:34 -05:00
|
|
|
};
|
|
|
|
|
|
2026-02-18 19:55:43 -05:00
|
|
|
# Reverse proxy
|
2026-02-18 14:57:21 -05:00
|
|
|
services.caddy = {
|
|
|
|
|
enable = true;
|
|
|
|
|
package = pkgs.caddy;
|
|
|
|
|
virtualHosts = {
|
2026-02-24 00:42:55 -05:00
|
|
|
"${matrixFqdn}" = {
|
2026-02-18 14:57:21 -05:00
|
|
|
extraConfig = ''
|
|
|
|
|
encode zstd gzip
|
|
|
|
|
reverse_proxy localhost:8008
|
|
|
|
|
'';
|
|
|
|
|
};
|
2026-02-24 00:42:55 -05:00
|
|
|
"${matrixFqdn}:8448" = {
|
2026-02-18 14:57:21 -05:00
|
|
|
extraConfig = ''
|
|
|
|
|
encode zstd gzip
|
|
|
|
|
reverse_proxy localhost:8008
|
|
|
|
|
'';
|
|
|
|
|
};
|
2026-02-24 00:42:55 -05:00
|
|
|
"${rtcFqdn}" = {
|
2026-02-18 14:57:21 -05:00
|
|
|
extraConfig = ''
|
|
|
|
|
@jwt_service {
|
|
|
|
|
path /sfu/get* /healthz*
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handle @jwt_service {
|
2026-02-23 22:30:45 -05:00
|
|
|
reverse_proxy localhost:8080
|
2026-02-18 14:57:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handle {
|
|
|
|
|
reverse_proxy localhost:7880 {
|
|
|
|
|
header_up Connection "upgrade"
|
|
|
|
|
header_up Upgrade {http.request.header.Upgrade}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-23 21:53:20 -05:00
|
|
|
# LiveKit JWT service
|
|
|
|
|
services.lk-jwt-service = {
|
2026-02-18 14:57:21 -05:00
|
|
|
enable = true;
|
2026-02-23 21:53:20 -05:00
|
|
|
port = 8080;
|
2026-02-24 00:08:30 -05:00
|
|
|
livekitUrl = "wss://rtc.wyattjmiller.com";
|
2026-02-23 21:53:20 -05:00
|
|
|
keyFile = livekitKeyFile;
|
|
|
|
|
};
|
2026-02-18 14:57:21 -05:00
|
|
|
|
2026-02-23 21:53:20 -05:00
|
|
|
# Generate LiveKit key if it doesn't exist
|
2026-02-24 00:42:55 -05:00
|
|
|
systemd.services = {
|
|
|
|
|
matrix-registration-token-gen = {
|
|
|
|
|
before = [ "tuwunel.service" ];
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
path = with pkgs; [ coreutils openssl ];
|
|
|
|
|
script = ''
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
|
|
if [ -f "${matrixRegistrationTokenFile}" ]; then
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
install -d -m 0700 "$(dirname "${matrixRegistrationTokenFile}")"
|
|
|
|
|
|
|
|
|
|
TOKEN="$(openssl rand -hex 32)"
|
|
|
|
|
|
|
|
|
|
umask 077
|
|
|
|
|
printf '%s\n' "$TOKEN" > "${matrixRegistrationTokenFile}"
|
|
|
|
|
'';
|
|
|
|
|
serviceConfig = {
|
|
|
|
|
Type = "oneshot";
|
|
|
|
|
User = "root";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
livekit-key-gen = {
|
|
|
|
|
before = [ "lk-jwt-service.service" "livekit.service" ];
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
path = with pkgs; [ coreutils openssl ];
|
|
|
|
|
script = ''
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
|
|
if [ -f "${livekitKeyFile}" ]; then
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
install -d -m 0700 "$(dirname "${livekitKeyFile}")"
|
|
|
|
|
|
|
|
|
|
API_KEY="$(openssl rand -hex 8)"
|
|
|
|
|
API_SECRET="$(openssl rand -hex 32)"
|
|
|
|
|
|
|
|
|
|
umask 077
|
|
|
|
|
printf '%s: %s\n' "$API_KEY" "$API_SECRET" > "${livekitKeyFile}"
|
|
|
|
|
'';
|
|
|
|
|
serviceConfig = {
|
|
|
|
|
Type = "oneshot";
|
|
|
|
|
User = "root";
|
|
|
|
|
};
|
2026-02-23 21:53:20 -05:00
|
|
|
};
|
2026-02-18 14:57:21 -05:00
|
|
|
};
|
2026-02-17 18:24:34 -05:00
|
|
|
|
|
|
|
|
system.stateVersion = "25.11";
|
|
|
|
|
}
|