From 5ac70a8f5b5cd1372ada3eb38b92485a7b79e35b Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Mon, 5 Aug 2024 19:59:45 +0530 Subject: cez/wireguard: add helper script --- os/cez/modules/wireguard.nix | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'os') diff --git a/os/cez/modules/wireguard.nix b/os/cez/modules/wireguard.nix index e6fa454..90cce8d 100644 --- a/os/cez/modules/wireguard.nix +++ b/os/cez/modules/wireguard.nix @@ -1,9 +1,30 @@ -{ config, ... }: let +{ config, pkgs, ... }: let domain = config.global.userdata.domain; + wgIface = "kay"; + + helper = pkgs.writeShellApplication { + name = "vpn"; + text = '' + note() { + command -v notify-send > /dev/null && + notify-send "󰒒 vpn" "$1" + + printf "\n%s\n" "$1" + } + + if systemctl status "wg-quick-${wgIface}.service" > /dev/null 2>&1; then + sudo -A systemctl stop "wg-quick-${wgIface}.service" && + note "connection was dropped" + else + sudo -A systemctl start "wg-quick-${wgIface}.service" && + note "traffic routed through ${wgIface}" + fi + ''; + }; in { sops.secrets."misc/wireguard" = {}; - networking.wg-quick.interfaces."kay" = { + networking.wg-quick.interfaces.${wgIface} = { autostart = false; address = [ "10.0.1.2/24" ]; dns = [ "10.0.1.1" ]; @@ -21,4 +42,6 @@ in { persistentKeepalive = 25; }]; }; + + environment.systemPackages = [ helper ]; } -- cgit v1.2.3