nixos/network-interfaces-systemd: support defaultGateway.interface
When interface and address are both specified, we can set Gateway= on the named interface. The existing logic assumes interface is not set (since it's guarded by assertion) so we now disable it when interface has a value. As a bonus, we now support the defaultGateway.metric option when interface is set.
This commit is contained in:
parent
088da23f9e
commit
c11b788d1a
@ -28,9 +28,24 @@ let
|
|||||||
# TODO: warn the user that any address configured on those interfaces will be useless
|
# TODO: warn the user that any address configured on those interfaces will be useless
|
||||||
++ concatMap (i: attrNames (filterAttrs (_: config: config.type != "internal") i.interfaces)) (attrValues cfg.vswitches);
|
++ concatMap (i: attrNames (filterAttrs (_: config: config.type != "internal") i.interfaces)) (attrValues cfg.vswitches);
|
||||||
|
|
||||||
|
defaultGateways = mkMerge (forEach [ cfg.defaultGateway cfg.defaultGateway6 ] (gateway:
|
||||||
|
optionalAttrs (gateway != null && gateway.interface != null) {
|
||||||
|
networks."40-${gateway.interface}" = {
|
||||||
|
matchConfig.Name = gateway.interface;
|
||||||
|
routes = [{
|
||||||
|
routeConfig = {
|
||||||
|
Gateway = gateway.address;
|
||||||
|
} // optionalAttrs (gateway.metric != null) {
|
||||||
|
Metric = gateway.metric;
|
||||||
|
};
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
genericNetwork = override:
|
genericNetwork = override:
|
||||||
let gateway = optional (cfg.defaultGateway != null && (cfg.defaultGateway.address or "") != "") cfg.defaultGateway.address
|
let gateway = optional (cfg.defaultGateway != null && (cfg.defaultGateway.address or "") != "" && cfg.defaultGateway.interface == null) cfg.defaultGateway.address
|
||||||
++ optional (cfg.defaultGateway6 != null && (cfg.defaultGateway6.address or "") != "") cfg.defaultGateway6.address;
|
++ optional (cfg.defaultGateway6 != null && (cfg.defaultGateway6.address or "") != "" && cfg.defaultGateway6.interface == null) cfg.defaultGateway6.address;
|
||||||
makeGateway = gateway: {
|
makeGateway = gateway: {
|
||||||
routeConfig = {
|
routeConfig = {
|
||||||
Gateway = gateway;
|
Gateway = gateway;
|
||||||
@ -198,6 +213,7 @@ in
|
|||||||
# initrd.systemd.network.enable. By setting the latter and not the
|
# initrd.systemd.network.enable. By setting the latter and not the
|
||||||
# former, the user retains full control over the configuration.
|
# former, the user retains full control over the configuration.
|
||||||
boot.initrd.systemd.network = mkMerge [
|
boot.initrd.systemd.network = mkMerge [
|
||||||
|
defaultGateways
|
||||||
(genericDhcpNetworks true)
|
(genericDhcpNetworks true)
|
||||||
interfaceNetworks
|
interfaceNetworks
|
||||||
bridgeNetworks
|
bridgeNetworks
|
||||||
@ -213,12 +229,6 @@ in
|
|||||||
assertions = [ {
|
assertions = [ {
|
||||||
assertion = cfg.defaultGatewayWindowSize == null;
|
assertion = cfg.defaultGatewayWindowSize == null;
|
||||||
message = "networking.defaultGatewayWindowSize is not supported by networkd.";
|
message = "networking.defaultGatewayWindowSize is not supported by networkd.";
|
||||||
} {
|
|
||||||
assertion = cfg.defaultGateway == null || cfg.defaultGateway.interface == null;
|
|
||||||
message = "networking.defaultGateway.interface is not supported by networkd.";
|
|
||||||
} {
|
|
||||||
assertion = cfg.defaultGateway6 == null || cfg.defaultGateway6.interface == null;
|
|
||||||
message = "networking.defaultGateway6.interface is not supported by networkd.";
|
|
||||||
} ] ++ flip mapAttrsToList cfg.bridges (n: { rstp, ... }: {
|
} ] ++ flip mapAttrsToList cfg.bridges (n: { rstp, ... }: {
|
||||||
assertion = !rstp;
|
assertion = !rstp;
|
||||||
message = "networking.bridges.${n}.rstp is not supported by networkd.";
|
message = "networking.bridges.${n}.rstp is not supported by networkd.";
|
||||||
@ -233,6 +243,7 @@ in
|
|||||||
mkMerge [ {
|
mkMerge [ {
|
||||||
enable = true;
|
enable = true;
|
||||||
}
|
}
|
||||||
|
defaultGateways
|
||||||
(genericDhcpNetworks false)
|
(genericDhcpNetworks false)
|
||||||
interfaceNetworks
|
interfaceNetworks
|
||||||
bridgeNetworks
|
bridgeNetworks
|
||||||
|
Loading…
Reference in New Issue
Block a user