From 17a3ba965c42fe1fffce6401fb5016af59226464 Mon Sep 17 00:00:00 2001 From: TheGeneralist <180094941+thegeneralist01@users.noreply.github.com> Date: Mon, 30 Nov 2026 23:36:57 +0100 Subject: [PATCH 1/3] thegeneralist(plex): proxy tailscale0 32400 through loopback --- hosts/thegeneralist/plex/default.nix | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/hosts/thegeneralist/plex/default.nix b/hosts/thegeneralist/plex/default.nix index 057f08d..70ba238 100644 --- a/hosts/thegeneralist/plex/default.nix +++ b/hosts/thegeneralist/plex/default.nix @@ -93,10 +93,35 @@ in }; # Allow Plex direct access from the home LAN subnet without exposing 32400 globally. - # tailscale0 is already trusted in modules/linux/tailscale.nix. + # Redirect Tailscale traffic targeting :32400 through a local TCP proxy so Plex + # sees 127.0.0.1 (Loopback) instead of the client's 100.64.0.0/10 Tailscale IP. networking.firewall.extraCommands = '' iptables -A nixos-fw -s 192.168.2.0/24 -p tcp --dport 32400 -j nixos-fw-accept + iptables -t nat -D PREROUTING -i tailscale0 -p tcp --dport 32400 -j REDIRECT --to-ports 32401 2>/dev/null || true + iptables -t nat -A PREROUTING -i tailscale0 -p tcp --dport 32400 -j REDIRECT --to-ports 32401 ''; + networking.firewall.extraStopCommands = '' + iptables -t nat -D PREROUTING -i tailscale0 -p tcp --dport 32400 -j REDIRECT --to-ports 32401 2>/dev/null || true + ''; + + systemd.sockets.plex-tailscale-proxy = { + description = "Socket for Tailscale Plex loopback proxy"; + wantedBy = [ "sockets.target" ]; + listenStreams = [ "0.0.0.0:32401" ]; + }; + + systemd.services.plex-tailscale-proxy = { + description = "Proxy Tailscale Plex traffic through loopback"; + wants = [ "plex.service" ]; + requires = [ "plex-tailscale-proxy.socket" ]; + after = [ "plex.service" "plex-tailscale-proxy.socket" ]; + serviceConfig = { + ExecStart = "${pkgs.systemd}/lib/systemd/systemd-socket-proxyd -c 1024 127.0.0.1:32400"; + DynamicUser = true; + PrivateTmp = true; + NoNewPrivileges = true; + }; + }; services.nginx.virtualHosts = { ${domain} = config; From 2fdead20b0b83f655cf74711218824ce77adce5d Mon Sep 17 00:00:00 2001 From: TheGeneralist <180094941+thegeneralist01@users.noreply.github.com> Date: Mon, 30 Nov 2026 23:43:06 +0100 Subject: [PATCH 2/3] thegeneralist(plex): move tailscale proxy port to 32499 --- hosts/thegeneralist/plex/default.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hosts/thegeneralist/plex/default.nix b/hosts/thegeneralist/plex/default.nix index 70ba238..522ac5d 100644 --- a/hosts/thegeneralist/plex/default.nix +++ b/hosts/thegeneralist/plex/default.nix @@ -97,17 +97,17 @@ in # sees 127.0.0.1 (Loopback) instead of the client's 100.64.0.0/10 Tailscale IP. networking.firewall.extraCommands = '' iptables -A nixos-fw -s 192.168.2.0/24 -p tcp --dport 32400 -j nixos-fw-accept - iptables -t nat -D PREROUTING -i tailscale0 -p tcp --dport 32400 -j REDIRECT --to-ports 32401 2>/dev/null || true - iptables -t nat -A PREROUTING -i tailscale0 -p tcp --dport 32400 -j REDIRECT --to-ports 32401 + iptables -t nat -D PREROUTING -i tailscale0 -p tcp --dport 32400 -j REDIRECT --to-ports 32499 2>/dev/null || true + iptables -t nat -A PREROUTING -i tailscale0 -p tcp --dport 32400 -j REDIRECT --to-ports 32499 ''; networking.firewall.extraStopCommands = '' - iptables -t nat -D PREROUTING -i tailscale0 -p tcp --dport 32400 -j REDIRECT --to-ports 32401 2>/dev/null || true + iptables -t nat -D PREROUTING -i tailscale0 -p tcp --dport 32400 -j REDIRECT --to-ports 32499 2>/dev/null || true ''; systemd.sockets.plex-tailscale-proxy = { description = "Socket for Tailscale Plex loopback proxy"; wantedBy = [ "sockets.target" ]; - listenStreams = [ "0.0.0.0:32401" ]; + listenStreams = [ "0.0.0.0:32499" ]; }; systemd.services.plex-tailscale-proxy = { From 78393fd2be100d3d69923dc71fca79ab9b0df252 Mon Sep 17 00:00:00 2001 From: TheGeneralist <180094941+thegeneralist01@users.noreply.github.com> Date: Mon, 30 Nov 2026 23:55:50 +0100 Subject: [PATCH 3/3] thegeneralist(plex): use DNAT to 100.108.125.63:32499 instead of REDIRECT --- hosts/thegeneralist/plex/default.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hosts/thegeneralist/plex/default.nix b/hosts/thegeneralist/plex/default.nix index 522ac5d..65fcea1 100644 --- a/hosts/thegeneralist/plex/default.nix +++ b/hosts/thegeneralist/plex/default.nix @@ -98,10 +98,11 @@ in networking.firewall.extraCommands = '' iptables -A nixos-fw -s 192.168.2.0/24 -p tcp --dport 32400 -j nixos-fw-accept iptables -t nat -D PREROUTING -i tailscale0 -p tcp --dport 32400 -j REDIRECT --to-ports 32499 2>/dev/null || true - iptables -t nat -A PREROUTING -i tailscale0 -p tcp --dport 32400 -j REDIRECT --to-ports 32499 + iptables -t nat -D PREROUTING -i tailscale0 -p tcp --dport 32400 -j DNAT --to-destination 100.108.125.63:32499 2>/dev/null || true + iptables -t nat -A PREROUTING -i tailscale0 -p tcp --dport 32400 -j DNAT --to-destination 100.108.125.63:32499 ''; networking.firewall.extraStopCommands = '' - iptables -t nat -D PREROUTING -i tailscale0 -p tcp --dport 32400 -j REDIRECT --to-ports 32499 2>/dev/null || true + iptables -t nat -D PREROUTING -i tailscale0 -p tcp --dport 32400 -j DNAT --to-destination 100.108.125.63:32499 2>/dev/null || true ''; systemd.sockets.plex-tailscale-proxy = {