diff options
author | sinanmohd <sinan@sinanmohd.com> | 2024-08-05 19:59:45 +0530 |
---|---|---|
committer | sinanmohd <sinan@sinanmohd.com> | 2024-08-05 20:00:11 +0530 |
commit | 5ac70a8f5b5cd1372ada3eb38b92485a7b79e35b (patch) | |
tree | abfe5a5eec7b0ba981f0759f443dc80c21c79592 | |
parent | 73ae22abcd10653efc4ef9fc6090e19a36c8dcf1 (diff) |
cez/wireguard: add helper script
-rw-r--r-- | os/cez/modules/wireguard.nix | 27 |
1 files changed, 25 insertions, 2 deletions
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 ]; } |