diff --git a/flake.nix b/flake.nix index 7ac02c3..082c2be 100644 --- a/flake.nix +++ b/flake.nix @@ -86,6 +86,8 @@ ./services/nginx.nix ./services/blog.nix ./services/coturn.nix + ./services/livekit.nix + ./services/lk-jwt.nix ./services/wireguard-outer.nix ./services/borgbackup-vps.nix ]; diff --git a/services/livekit.nix b/services/livekit.nix new file mode 100644 index 0000000..2c37081 --- /dev/null +++ b/services/livekit.nix @@ -0,0 +1,59 @@ +{ config, pkgs, ... }: + +{ + sops.secrets."livekit/api_key" = { + sopsFile = ./secrets/livekit_vps.yaml; + mode = "0400"; + }; + sops.secrets."livekit/api_secret" = { + sopsFile = ./secrets/livekit_vps.yaml; + mode = "0400"; + }; + + # WebRTC media (UDP) and ICE TCP fallback. HTTP signaling goes through nginx. + networking.firewall = { + allowedTCPPorts = [ 7881 ]; + allowedUDPPortRanges = [ + { + from = 50000; + to = 50200; + } + ]; + }; + + systemd.services.livekit = { + description = "LiveKit SFU server"; + wantedBy = [ "multi-user.target" ]; + after = [ "network-online.target" ]; + wants = [ "network-online.target" ]; + + serviceConfig = { + DynamicUser = true; + RuntimeDirectory = "livekit"; + Restart = "always"; + RestartSec = 5; + }; + + script = '' + API_KEY=$(cat ${config.sops.secrets."livekit/api_key".path}) + API_SECRET=$(cat ${config.sops.secrets."livekit/api_secret".path}) + + cat > /run/livekit/config.yaml <