mirror of
https://github.com/SebastianWendel/nixpkgs.git
synced 2024-09-21 04:49:01 +02:00
nixos/dhcpcd: Respect per interface dhcp options
This commit is contained in:
parent
7005e289da
commit
c417012c1b
|
@ -8,15 +8,28 @@ let
|
||||||
|
|
||||||
cfg = config.networking.dhcpcd;
|
cfg = config.networking.dhcpcd;
|
||||||
|
|
||||||
|
interfaces = attrValues config.networking.interfaces;
|
||||||
|
|
||||||
|
enableDHCP = config.networking.useDHCP || any (i: i.useDHCP == true) interfaces;
|
||||||
|
|
||||||
# Don't start dhcpcd on explicitly configured interfaces or on
|
# Don't start dhcpcd on explicitly configured interfaces or on
|
||||||
# interfaces that are part of a bridge, bond or sit device.
|
# interfaces that are part of a bridge, bond or sit device.
|
||||||
ignoredInterfaces =
|
ignoredInterfaces =
|
||||||
map (i: i.name) (filter (i: if i.useDHCP != null then i.useDHCP else i.ip4 != [ ] || i.ipAddress != null) (attrValues config.networking.interfaces))
|
map (i: i.name) (filter (i: if i.useDHCP != null then i.useDHCP else i.ip4 != [ ] || i.ipAddress != null) interfaces)
|
||||||
++ mapAttrsToList (i: _: i) config.networking.sits
|
++ mapAttrsToList (i: _: i) config.networking.sits
|
||||||
++ concatLists (attrValues (mapAttrs (n: v: v.interfaces) config.networking.bridges))
|
++ concatLists (attrValues (mapAttrs (n: v: v.interfaces) config.networking.bridges))
|
||||||
++ concatLists (attrValues (mapAttrs (n: v: v.interfaces) config.networking.bonds))
|
++ concatLists (attrValues (mapAttrs (n: v: v.interfaces) config.networking.bonds))
|
||||||
++ config.networking.dhcpcd.denyInterfaces;
|
++ config.networking.dhcpcd.denyInterfaces;
|
||||||
|
|
||||||
|
arrayAppendOrNull = a1: a2: if a1 == null && a2 == null then null
|
||||||
|
else if a1 == null then a2 else if a2 == null then a1
|
||||||
|
else a1 ++ a2;
|
||||||
|
|
||||||
|
# If dhcp is disabled but explicit interfaces are enabled,
|
||||||
|
# we need to provide dhcp just for those interfaces.
|
||||||
|
allowInterfaces = arrayAppendOrNull cfg.allowInterfaces
|
||||||
|
(if !cfg.useDHCP && enableDHCP then map (i: i.name) (filter (i: i.useDHCP == true) interfaces) else null);
|
||||||
|
|
||||||
# Config file adapted from the one that ships with dhcpcd.
|
# Config file adapted from the one that ships with dhcpcd.
|
||||||
dhcpcdConf = pkgs.writeText "dhcpcd.conf"
|
dhcpcdConf = pkgs.writeText "dhcpcd.conf"
|
||||||
''
|
''
|
||||||
|
@ -41,7 +54,7 @@ let
|
||||||
denyinterfaces ${toString ignoredInterfaces} lo peth* vif* tap* tun* virbr* vnet* vboxnet* sit*
|
denyinterfaces ${toString ignoredInterfaces} lo peth* vif* tap* tun* virbr* vnet* vboxnet* sit*
|
||||||
|
|
||||||
# Use the list of allowed interfaces if specified
|
# Use the list of allowed interfaces if specified
|
||||||
${optionalString (cfg.allowInterfaces != null) "allowinterfaces ${toString cfg.allowInterfaces}"}
|
${optionalString (allowInterfaces != null) "allowinterfaces ${toString allowInterfaces}"}
|
||||||
|
|
||||||
${cfg.extraConfig}
|
${cfg.extraConfig}
|
||||||
'';
|
'';
|
||||||
|
@ -133,7 +146,7 @@ in
|
||||||
|
|
||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = mkIf config.networking.useDHCP {
|
config = mkIf enableDHCP {
|
||||||
|
|
||||||
systemd.services.dhcpcd =
|
systemd.services.dhcpcd =
|
||||||
{ description = "DHCP Client";
|
{ description = "DHCP Client";
|
||||||
|
|
Loading…
Reference in a new issue