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.)
This commit is contained in:
@@ -164,6 +164,15 @@ let
|
|||||||
of the wireguard network has to be adjusted as well.
|
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
|
optionalString interfaceCfg.allowedIPsAsRoutes
|
||||||
(concatMapStringsSep "\n"
|
(concatMapStringsSep "\n"
|
||||||
(allowedIP:
|
(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);
|
) peer.allowedIPs);
|
||||||
in ''
|
in ''
|
||||||
${wg_setup}
|
${wg_setup}
|
||||||
|
|||||||
Reference in New Issue
Block a user