From 306e320a3a2819659c71ea46d7239e7f778a3561 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Wed, 20 Aug 2025 12:28:13 -0400 Subject: [PATCH] create 'lib.vpnNamespaceOpenPort' --- lib.nix | 21 +++++++++++++++++++++ services/bitmagnet.nix | 19 ++++--------------- services/qbittorrent.nix | 18 +----------------- 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/lib.nix b/lib.nix index ef658f0..45872ba 100644 --- a/lib.nix +++ b/lib.nix @@ -54,5 +54,26 @@ inputs.nixpkgs.lib.extend ( "-march=znver3" "-mtune=znver3" ]; + + vpnNamespaceOpenPort = + port: + { ... }: + { + vpnNamespaces.wg = { + portMappings = [ + { + from = port; + to = port; + } + ]; + + openVPNPorts = [ + { + port = port; + protocol = "both"; + } + ]; + }; + }; } ) diff --git a/services/bitmagnet.nix b/services/bitmagnet.nix index 5396fe3..571112a 100644 --- a/services/bitmagnet.nix +++ b/services/bitmagnet.nix @@ -2,24 +2,13 @@ pkgs, service_configs, config, + lib, ... }: { - vpnNamespaces.wg = { - portMappings = [ - { - from = service_configs.ports.bitmagnet; - to = service_configs.ports.bitmagnet; - } - ]; - - openVPNPorts = [ - { - port = service_configs.ports.bitmagnet; - protocol = "both"; - } - ]; - }; + imports = [ + (lib.vpnNamespaceOpenPort service_configs.ports.bitmagnet) + ]; services.bitmagnet = { enable = true; diff --git a/services/qbittorrent.nix b/services/qbittorrent.nix index 1b23100..dc8482c 100644 --- a/services/qbittorrent.nix +++ b/services/qbittorrent.nix @@ -13,25 +13,9 @@ config.services.qbittorrent.serverConfig.Preferences.Downloads.TempPath "${config.services.qbittorrent.profileDir}/qBittorrent" ]) + (lib.vpnNamespaceOpenPort config.services.qbittorrent.webuiPort) ]; - # network namespace that is proxied through mullvad - vpnNamespaces.wg = { - portMappings = [ - { - from = config.services.qbittorrent.webuiPort; - to = config.services.qbittorrent.webuiPort; - } - ]; - - openVPNPorts = [ - { - port = config.services.qbittorrent.webuiPort; - protocol = "both"; - } - ]; - }; - services.qbittorrent = { enable = true; webuiPort = service_configs.ports.torrent;