mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-02-23 04:25:14 +00:00
nixos/networkd: reimplement useDHCP in a sensible way
This commit is contained in:
parent
dd3044575e
commit
d30dbf38b9
@ -43,12 +43,6 @@ in
|
|||||||
} {
|
} {
|
||||||
assertion = cfg.defaultGateway6 == null || cfg.defaultGateway6.interface == null;
|
assertion = cfg.defaultGateway6 == null || cfg.defaultGateway6.interface == null;
|
||||||
message = "networking.defaultGateway6.interface is not supported by networkd.";
|
message = "networking.defaultGateway6.interface is not supported by networkd.";
|
||||||
} {
|
|
||||||
assertion = cfg.useDHCP == false;
|
|
||||||
message = ''
|
|
||||||
networking.useDHCP is not supported by networkd.
|
|
||||||
Please use per interface configuration and set the global option to false.
|
|
||||||
'';
|
|
||||||
} ] ++ 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.";
|
||||||
@ -92,6 +86,40 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
networks."99-ethernet-default-dhcp" = lib.mkIf cfg.useDHCP {
|
||||||
|
# We want to match physical ethernet interfaces as commonly
|
||||||
|
# found on laptops, desktops and servers, to provide an
|
||||||
|
# "out-of-the-box" setup that works for common cases. This
|
||||||
|
# heuristic isn't perfect (it could match interfaces with
|
||||||
|
# custom names that _happen_ to start with en or eth), but
|
||||||
|
# should be good enough to make the common case easy and can
|
||||||
|
# be overridden on a case-by-case basis using
|
||||||
|
# higher-priority networks or by disabling useDHCP.
|
||||||
|
|
||||||
|
# Type=ether matches veth interfaces as well, and this is
|
||||||
|
# more likely to result in interfaces being configured to
|
||||||
|
# use DHCP when they shouldn't.
|
||||||
|
|
||||||
|
# We set RequiredForOnline to false, because it's fairly
|
||||||
|
# common for such devices to have multiple interfaces and
|
||||||
|
# only one of them to be connected (e.g. a laptop with
|
||||||
|
# ethernet and WiFi interfaces). Maybe one day networkd will
|
||||||
|
# support "any"-style RequiredForOnline...
|
||||||
|
matchConfig.Name = ["en*" "eth*"];
|
||||||
|
DHCP = "yes";
|
||||||
|
linkConfig.RequiredForOnline = lib.mkDefault false;
|
||||||
|
};
|
||||||
|
networks."99-wireless-client-dhcp" = lib.mkIf cfg.useDHCP {
|
||||||
|
# Like above, but this is much more likely to be correct.
|
||||||
|
matchConfig.WLANInterfaceType = "station";
|
||||||
|
DHCP = "yes";
|
||||||
|
linkConfig.RequiredForOnline = lib.mkDefault false;
|
||||||
|
# We also set the route metric to one more than the default
|
||||||
|
# of 1024, so that Ethernet is preferred if both are
|
||||||
|
# available.
|
||||||
|
dhcpV4Config.RouteMetric = 1025;
|
||||||
|
ipv6AcceptRAConfig.RouteMetric = 1025;
|
||||||
|
};
|
||||||
networks."40-${i.name}" = mkMerge [ (genericNetwork id) {
|
networks."40-${i.name}" = mkMerge [ (genericNetwork id) {
|
||||||
name = mkDefault i.name;
|
name = mkDefault i.name;
|
||||||
DHCP = mkForce (dhcpStr
|
DHCP = mkForce (dhcpStr
|
||||||
|
Loading…
Reference in New Issue
Block a user