diff options
author | Bjørn Forsman <bjorn.forsman@gmail.com> | 2023-09-21 22:19:21 +0200 |
---|---|---|
committer | Bjørn Forsman <bjorn.forsman@gmail.com> | 2023-09-21 22:19:21 +0200 |
commit | ed7c0c6e7579db97c8889f5bd2bdd8a66f60aab9 (patch) | |
tree | 7bf260ad7be74eca24e66125240b8a2ff31c9814 | |
parent | 8b5ab8341e33322e5b66fb46ce23d724050f6606 (diff) | |
download | nixlib-ed7c0c6e7579db97c8889f5bd2bdd8a66f60aab9.tar nixlib-ed7c0c6e7579db97c8889f5bd2bdd8a66f60aab9.tar.gz nixlib-ed7c0c6e7579db97c8889f5bd2bdd8a66f60aab9.tar.bz2 nixlib-ed7c0c6e7579db97c8889f5bd2bdd8a66f60aab9.tar.lz nixlib-ed7c0c6e7579db97c8889f5bd2bdd8a66f60aab9.tar.xz nixlib-ed7c0c6e7579db97c8889f5bd2bdd8a66f60aab9.tar.zst nixlib-ed7c0c6e7579db97c8889f5bd2bdd8a66f60aab9.zip |
nixos/wireguard: add metric option
This new option, networking.wireguard.interfaces.NAME.metric, allows increasing the metric of the routes, effectively lowering priority. (I'm using high metric to allow having the Wireguard interface always up, even when the client machines are on their home network. Before I had to stop the interface when home to avoid packet routing issues.)
-rw-r--r-- | nixos/modules/services/networking/wireguard.nix | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/nixos/modules/services/networking/wireguard.nix b/nixos/modules/services/networking/wireguard.nix index 21473388d76e..d4099be12a27 100644 --- a/nixos/modules/services/networking/wireguard.nix +++ b/nixos/modules/services/networking/wireguard.nix @@ -164,6 +164,15 @@ let of the wireguard network has to be adjusted as well. ''; }; + + metric = mkOption { + default = null; + type = with types; nullOr int; + example = 700; + description = lib.mdDoc '' + Set the metric of routes related to this Wireguard interface. + ''; + }; }; }; @@ -395,7 +404,7 @@ let optionalString interfaceCfg.allowedIPsAsRoutes (concatMapStringsSep "\n" (allowedIP: - ''${ip} route replace "${allowedIP}" dev "${interfaceName}" table "${interfaceCfg.table}"'' + ''${ip} route replace "${allowedIP}" dev "${interfaceName}" table "${interfaceCfg.table}" ${optionalString (interfaceCfg.metric != null) "metric ${toString interfaceCfg.metric}"}'' ) peer.allowedIPs); in '' ${wg_setup} |