Add rtmp back, we're so back

This commit is contained in:
Bun 2025-07-16 01:47:15 -04:00
parent bf8d0f7be3
commit 7e067eb274
3 changed files with 54 additions and 2 deletions

View file

@ -1,6 +1,9 @@
{ ... }: { ... }:
{ {
imports = [ ./nixfox ]; imports = [
./nixfox
./rtmp
];
services.nginx.enable = true; services.nginx.enable = true;
} }

View file

@ -1,7 +1,7 @@
{ config, pkgs, ... }: { config, pkgs, ... }:
{ {
services.nginx.virtualHosts = { services.nginx.virtualHosts = {
"nixfox.ca" = { "${config.vars.primeDomain}" = {
default = true; default = true;
enableACME = true; enableACME = true;
addSSL = true; addSSL = true;

View file

@ -0,0 +1,49 @@
{ config, lib, pkgs, nodes, ... }:
{
services.nginx = {
virtualHosts."stream.${config.vars.primeDomain}" = {
enableACME = true;
addSSL = true;
root = "/var/www/rtmp";
locations."/".extraConfig = ''
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Range, Origin, X-Requested-With, Content-Type, Accept' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length, Content-Range' always;
'';
};
additionalModules = with pkgs.nginxModules; [ rtmp ];
appendConfig = ''
rtmp {
server {
listen [::]:1935;
chunk_size 4096;
allow publish all;
application stream {
live on;
allow play all;
hls on;
hls_path /var/www/rtmp/;
hls_base_url https://stream.${config.vars.primeDomain}/;
hls_playlist_length 40;
}
}
}
'';
};
# NixOS sandboxes this path by default. Allow it to be unsandboxed
systemd.services.nginx.serviceConfig.ReadWritePaths = [ "/var/www/rtmp" ];
# Allow rtmp to select hosts
networking.firewall.extraInputRules = let
targetHosts = lib.attrValues (lib.mapAttrs (_: node: node.config.deployment.targetHost) nodes);
in ''
ip6 saddr { ${lib.concatStringsSep ", " targetHosts} } tcp dport 1935 accept
'';
}