modules/wireguard: del ip route when wireguard is stopping
This commit is contained in:
parent
a67cadfd8d
commit
59632cb3f7
1 changed files with 17 additions and 3 deletions
|
@ -2,6 +2,11 @@
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.local.services.vpn.wireguard;
|
cfg = config.local.services.vpn.wireguard;
|
||||||
|
|
||||||
|
addrsViaDefaultInterface = [
|
||||||
|
# cache.nixos.org
|
||||||
|
"151.101.86.217/32"
|
||||||
|
];
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.local.services.vpn.wireguard = with lib; {
|
options.local.services.vpn.wireguard = with lib; {
|
||||||
|
@ -46,9 +51,18 @@ in
|
||||||
postUp = ''
|
postUp = ''
|
||||||
addr=`${pkgs.iproute}/bin/ip route | ${pkgs.gawk}/bin/awk '/default/ {print $3; exit}'`
|
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}'`
|
interface=`${pkgs.iproute}/bin/ip route | ${pkgs.gawk}/bin/awk '/default/ {print $5; exit}'`
|
||||||
# don't use wg with cache.nixos.org
|
'' + lib.concatLines (map
|
||||||
${pkgs.iproute}/bin/ip route add 151.101.86.217/32 via $addr dev $interface
|
(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 = [
|
peers = [
|
||||||
# For a client configuration, one peer entry for the server will suffice.
|
# For a client configuration, one peer entry for the server will suffice.
|
||||||
|
|
Loading…
Reference in a new issue