From 8d0d4995c388062f295e6c1fb1e8c9e5c3259c52 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Fri, 27 Dec 2024 19:46:21 +0100 Subject: feat(ev): add qbittorrent --- nixos/lib.nix | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'nixos/lib.nix') diff --git a/nixos/lib.nix b/nixos/lib.nix index a2d8193..7880cc7 100644 --- a/nixos/lib.nix +++ b/nixos/lib.nix @@ -9,4 +9,24 @@ in unitConfig.JoinsNamespaceOf = "netns@${ns}.service"; serviceConfig.NetworkNamespacePath = "/var/run/netns/${ns}"; }; + + mkPortProxy = service: ns: port: { + description = "Forward to ${service} in network namespace ${ns}"; + requires = ["${service}.service"]; + after = ["${service}.service"]; + partOf = ["${service}.service"]; + serviceConfig = { + Restart = "on-failure"; + TimeoutStopSec = 300; + }; + wantedBy = ["multi-user.target"]; + script = + let + pkgs = nixpkgs.pkgs; + in + '' + ${pkgs.iproute2}/bin/ip netns exec ${ns} ${pkgs.iproute2}/bin/ip link set dev lo up + ${pkgs.socat}/bin/socat tcp-listen:${toString port},fork,reuseaddr exec:'${pkgs.iproute2}/bin/ip netns exec ${ns} ${pkgs.socat}/bin/socat STDIO "tcp-connect:localhost:${toString port}"',nofork + ''; + }; } -- cgit v1.2.3