summaryrefslogtreecommitdiffstats
path: root/nixos/modules/tasks/network-interfaces-scripted.nix
diff options
context:
space:
mode:
authorFranz Pletz <fpletz@fnordicwalking.de>2017-09-01 06:24:37 +0200
committerFranz Pletz <fpletz@fnordicwalking.de>2017-09-28 02:14:07 +0200
commitd0435ba032473f89fad8b6425bb3feee3d6fd718 (patch)
treeb3621bfa299f83edddec75680975604826834617 /nixos/modules/tasks/network-interfaces-scripted.nix
parent0a6fca15fd7bcafe2f98f05bd7a3ec816e2f3959 (diff)
network-interfaces: device routes for default gateway
Iff interface is set, it makes sense to add device route by default.
Diffstat (limited to 'nixos/modules/tasks/network-interfaces-scripted.nix')
-rw-r--r--nixos/modules/tasks/network-interfaces-scripted.nix20
1 files changed, 14 insertions, 6 deletions
diff --git a/nixos/modules/tasks/network-interfaces-scripted.nix b/nixos/modules/tasks/network-interfaces-scripted.nix
index 3512296dff4a..e92c9bc27def 100644
--- a/nixos/modules/tasks/network-interfaces-scripted.nix
+++ b/nixos/modules/tasks/network-interfaces-scripted.nix
@@ -122,24 +122,32 @@ let
# 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 ${optionalString (cfg.defaultGateway.metric != null)
+ ${optionalString (cfg.defaultGateway.interface != null) ''
+ ip route replace ${cfg.defaultGateway.address} dev ${cfg.defaultGateway.interface} ${optionalString (cfg.defaultGateway.metric != null)
+ "metric ${toString cfg.defaultGateway.metric}"
+ } proto static
+ ''}
+ ip route replace 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}"} proto static || true
+ "dev ${cfg.defaultGateway.interface}"} proto static
''}
${optionalString (cfg.defaultGateway6 != null && cfg.defaultGateway6.address != "") ''
- # FIXME: get rid of "|| true" (necessary to make it idempotent).
- ip -6 route add ::/0 ${optionalString (cfg.defaultGateway6.metric != null)
+ ${optionalString (cfg.defaultGateway6.interface != null) ''
+ ip -6 route replace ${cfg.defaultGateway6.address} dev ${cfg.defaultGateway6.interface} ${optionalString (cfg.defaultGateway6.metric != null)
+ "metric ${toString cfg.defaultGateway6.metric}"
+ } proto static
+ ''}
+ ip -6 route replace default ${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)
- "dev ${cfg.defaultGateway6.interface}"} proto static || true
+ "dev ${cfg.defaultGateway6.interface}"} proto static
''}
'';
};