From 74bc41f8cd6bf10ad57e6b3fe04d06ac4c0b2fc4 Mon Sep 17 00:00:00 2001 From: Lu Wang Date: Tue, 3 Dec 2024 21:45:59 +0800 Subject: [PATCH] services/enthalpy: implement handcrafted script to switch netns --- nixos/modules/services/enthalpy/services.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nixos/modules/services/enthalpy/services.nix b/nixos/modules/services/enthalpy/services.nix index 1c4bd6c..9b9524e 100644 --- a/nixos/modules/services/enthalpy/services.nix +++ b/nixos/modules/services/enthalpy/services.nix @@ -118,5 +118,17 @@ in wantedBy = [ "multi-user.target" ]; }; }) + + (mkIf (cfg.users != { }) { + environment.systemPackages = with pkgs; [ + (pkgs.writeShellApplication { + name = "netns-run-default"; + runtimeInputs = with pkgs; [ util-linux ]; + text = '' + pkexec nsenter -t $$ -e --mount=/proc/1/ns/mnt --net=/proc/1/ns/net -S "$(id -u)" -G "$(id -g)" --wdns="$PWD" "$@" + ''; + }) + ]; + }) ]); }