From 8b83d306199622b3b5a952d84b776e80a063be0c Mon Sep 17 00:00:00 2001 From: Collin Williams <96917990+bluedragon1221@users.noreply.github.com> Date: Wed, 26 Aug 2026 13:02:54 -0500 Subject: try to switch between full tunnel and split tunnel without rebuilding (not working yet) --- hosts/mercury/wireguard.nix | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/hosts/mercury/wireguard.nix b/hosts/mercury/wireguard.nix index 1af84c0..35c6a24 100644 --- a/hosts/mercury/wireguard.nix +++ b/hosts/mercury/wireguard.nix @@ -4,8 +4,36 @@ pkgs, lib, ... -}: { - environment.systemPackages = [pkgs.wireguard-tools]; +}: let + wg-mode = pkgs.writeShellScriptBin "wg-mode" '' + PEER_KEY="${hosts.ganymede.wg_pubkey}" + IFACE="wg0" + case "$1" in + full) + sudo bash -c " + wg set '$IFACE' peer '$PEER_KEY' allowed-ips 0.0.0.0/0,::/0 + ip route add default dev '$IFACE' metric 100 + " + echo "Switched $IFACE to Full Tunnel" + ;; + split) + sudo bash -c " + ip route del default dev '$IFACE' metric 100 + wg set '$IFACE' peer '$PEER_KEY' allowed-ips 10.0.0.0/24 + " + echo "Switched $IFACE to Split Tunnel" + ;; + *) + echo "Usage: wg-mode [full|split]" + exit 1 + ;; + esac + ''; +in { + environment.systemPackages = [ + pkgs.wireguard-tools + wg-mode + ]; systemd.services.udp2raw-client = { description = "udp2raw WireGuard transport"; -- cgit v1.3.1