modularized yshtola

pulled out the FQDNs and repeating strings that i don't need repeated
This commit is contained in:
2026-02-24 00:42:55 -05:00
parent 6b586d80ab
commit b3954838d2

View File

@@ -3,6 +3,11 @@
userName, userName,
... ...
}: let }: let
# INFO: set these to your liking
matrixFqdn = "chat.wyattjmiller.com";
rtcFqdn = "rtc.wyattjmiller.com";
supportEmail = "wyatt@wyattjmiller.com";
livekitKeyFile = "/var/lib/livekit/livekit.key"; livekitKeyFile = "/var/lib/livekit/livekit.key";
matrixRegistrationTokenFile = "/var/lib/matrix.key"; matrixRegistrationTokenFile = "/var/lib/matrix.key";
in { in {
@@ -19,8 +24,6 @@ in {
# Custom kernel/boot stuff # Custom kernel/boot stuff
boot.kernelPackages = pkgs.linuxPackages_latest; boot.kernelPackages = pkgs.linuxPackages_latest;
# boot.loader.systemd-boot.enable = true; # TODO: check on this
# boot.loader.efi.canTouchEfiVariables = true;
# Set your timezone # Set your timezone
time.timeZone = "America/Detroit"; time.timeZone = "America/Detroit";
@@ -117,14 +120,13 @@ in {
package = pkgs.matrix-tuwunel; package = pkgs.matrix-tuwunel;
settings = { settings = {
global = { global = {
server_name = "chat.wyattjmiller.com"; server_name = matrixFqdn;
allow_encryption = true; allow_encryption = true;
allow_federation = true; allow_federation = true;
allow_registration = true; allow_registration = true;
registration_token = matrixRegistrationTokenFile; registration_token = matrixRegistrationTokenFile;
allow_unstable_room_versions = false; allow_unstable_room_versions = false;
allow_experimental_room_versions = false; allow_experimental_room_versions = false;
# encryption_enabled_by_default_for_room_type = false;
zstd_compression = true; zstd_compression = true;
new_user_displayname_suffix = ""; new_user_displayname_suffix = "";
max_request_size = 1048575600; # 100MB in bytes, for file uploads max_request_size = 1048575600; # 100MB in bytes, for file uploads
@@ -138,36 +140,20 @@ in {
port = [ 8008 ]; port = [ 8008 ];
well_known = { well_known = {
client = "https://chat.wyattjmiller.com"; client = "https://${matrixFqdn}";
server = "chat.wyattjmiller.com:443"; server = "${matrixFqdn}:443";
support_email = "wyatt@wyattjmiller.com"; support_email = supportEmail;
support_mxid = "@wymiller:chat.wyattjmiller.com"; support_mxid = "@wymiller:${matrixFqdn}";
rtc_transports = [{ rtc_transports = [{
type = "livekit"; type = "livekit";
livekit_service_url = "https://rtc.wyattjmiller.com"; livekit_service_url = "https://${rtcFqdn}";
}]; }];
}; };
}; };
}; };
}; };
# TURN/STUN server
services.coturn = {
enable = true;
no-cli = false;
no-tcp-relay = false;
realm = "turn.wyattjmiller.com";
min-port = 49000;
max-port = 50000;
# TODO: fill out this extraConfig option a bit more with denial of private IP addresses
extraConfig = ''
verbose
no-multicast-peers
'';
};
# LiveKit (Matrix RTC) # LiveKit (Matrix RTC)
services.livekit = { services.livekit = {
enable = true; enable = true;
@@ -188,19 +174,19 @@ in {
enable = true; enable = true;
package = pkgs.caddy; package = pkgs.caddy;
virtualHosts = { virtualHosts = {
"chat.wyattjmiller.com" = { "${matrixFqdn}" = {
extraConfig = '' extraConfig = ''
encode zstd gzip encode zstd gzip
reverse_proxy localhost:8008 reverse_proxy localhost:8008
''; '';
}; };
"chat.wyattjmiller.com:8448" = { "${matrixFqdn}:8448" = {
extraConfig = '' extraConfig = ''
encode zstd gzip encode zstd gzip
reverse_proxy localhost:8008 reverse_proxy localhost:8008
''; '';
}; };
"rtc.wyattjmiller.com" = { "${rtcFqdn}" = {
extraConfig = '' extraConfig = ''
@jwt_service { @jwt_service {
path /sfu/get* /healthz* path /sfu/get* /healthz*
@@ -230,7 +216,32 @@ in {
}; };
# Generate LiveKit key if it doesn't exist # Generate LiveKit key if it doesn't exist
systemd.services.livekit-key = { 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" ]; before = [ "lk-jwt-service.service" "livekit.service" ];
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
path = with pkgs; [ coreutils openssl ]; path = with pkgs; [ coreutils openssl ];
@@ -246,8 +257,6 @@ in {
API_KEY="$(openssl rand -hex 8)" API_KEY="$(openssl rand -hex 8)"
API_SECRET="$(openssl rand -hex 32)" API_SECRET="$(openssl rand -hex 32)"
# keyFile format for nixpkgs services.livekit.keyFile:
# a YAML map of apiKey -> apiSecret (no surrounding "keys:" key)
umask 077 umask 077
printf '%s: %s\n' "$API_KEY" "$API_SECRET" > "${livekitKeyFile}" printf '%s: %s\n' "$API_KEY" "$API_SECRET" > "${livekitKeyFile}"
''; '';
@@ -256,6 +265,7 @@ in {
User = "root"; User = "root";
}; };
}; };
};
system.stateVersion = "25.11"; system.stateVersion = "25.11";
} }