From 59632cb3f7519ceb4531c031f257ed1bdd44152b Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Sat, 15 Jun 2024 09:46:07 +0300 Subject: [PATCH] modules/wireguard: del ip route when wireguard is stopping --- .../nixos/services/vpn/wireguard/client.nix | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/modules/nixos/services/vpn/wireguard/client.nix b/modules/nixos/services/vpn/wireguard/client.nix index 9be3134..a187b7b 100644 --- a/modules/nixos/services/vpn/wireguard/client.nix +++ b/modules/nixos/services/vpn/wireguard/client.nix @@ -2,6 +2,11 @@ let cfg = config.local.services.vpn.wireguard; + + addrsViaDefaultInterface = [ + # cache.nixos.org + "151.101.86.217/32" + ]; in { options.local.services.vpn.wireguard = with lib; { @@ -46,9 +51,18 @@ in postUp = '' addr=`${pkgs.iproute}/bin/ip route | ${pkgs.gawk}/bin/awk '/default/ {print $3; exit}'` interface=`${pkgs.iproute}/bin/ip route | ${pkgs.gawk}/bin/awk '/default/ {print $5; exit}'` - # don't use wg with cache.nixos.org - ${pkgs.iproute}/bin/ip route add 151.101.86.217/32 via $addr dev $interface - ''; + '' + lib.concatLines (map + (addr: "${pkgs.iproute}/bin/ip route add ${addr} via $addr dev $interface") + addrsViaDefaultInterface + ); + + preDown = '' + addr=`${pkgs.iproute}/bin/ip route | ${pkgs.gawk}/bin/awk '/default/ {print $3; exit}'` + interface=`${pkgs.iproute}/bin/ip route | ${pkgs.gawk}/bin/awk '/default/ {print $5; exit}'` + '' + lib.concatLines (map + (addr: "${pkgs.iproute}/bin/ip route del ${addr} via $addr dev $interface") + addrsViaDefaultInterface + ); peers = [ # For a client configuration, one peer entry for the server will suffice.