network-interfaces service: add metric option for defaultGateways

This commit is contained in:
Franz Pletz 2017-02-09 23:09:07 +01:00
parent 9973f490f2
commit 3fd44e2912
No known key found for this signature in database
GPG key ID: 846FDED7792617B4
2 changed files with 14 additions and 3 deletions

View file

@ -104,15 +104,19 @@ in
# Set the default gateway.
${optionalString (cfg.defaultGateway != null && cfg.defaultGateway.address != "") ''
# FIXME: get rid of "|| true" (necessary to make it idempotent).
ip route add default via "${cfg.defaultGateway.address}" ${
ip route add default ${optionalString (cfg.defaultGateway.metric != null)
"metric ${toString cfg.defaultGateway.metric}"
} via "${cfg.defaultGateway.address}" ${
optionalString (cfg.defaultGatewayWindowSize != null)
"window ${toString cfg.defaultGatewayWindowSize}"} ${
optionalString (cfg.defaultGateway.interface != null)
"dev ${cfg.defaultGateway.interface}"}|| true
"dev ${cfg.defaultGateway.interface}"} || true
''}
${optionalString (cfg.defaultGateway6 != null && cfg.defaultGateway6.address != "") ''
# FIXME: get rid of "|| true" (necessary to make it idempotent).
ip -6 route add ::/0 via "${cfg.defaultGateway6.address}" ${
ip -6 route add ::/0 ${optionalString (cfg.defaultGateway6.metric != null)
"metric ${toString cfg.defaultGateway6.metric}"
} via "${cfg.defaultGateway6.address}" ${
optionalString (cfg.defaultGatewayWindowSize != null)
"window ${toString cfg.defaultGatewayWindowSize}"} ${
optionalString (cfg.defaultGateway6.interface != null)

View file

@ -134,6 +134,13 @@ let
description = "The default gateway interface.";
};
metric = mkOption {
type = types.nullOr types.int;
default = null;
example = 42;
description = "The default gateway metric/preference.";
};
};
};