nixos/network-interfaces: Support the old ip configuration convention

This commit is contained in:
William A. Kennington III 2014-08-30 08:00:10 -07:00
parent 86c0f8c549
commit 4d8390be60
2 changed files with 36 additions and 17 deletions

View file

@ -11,7 +11,7 @@ let
# 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: i.ip4 != [ ]) (attrValues config.networking.interfaces)) map (i: i.name) (filter (i: i.ip4 != [ ] || i.ipAddress != null) (attrValues config.networking.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))

View file

@ -68,36 +68,48 @@ let
ipAddress = mkOption { ipAddress = mkOption {
default = null; default = null;
example = "10.0.0.1";
type = types.nullOr types.str;
description = '' description = ''
Defunct, create an address in the ip4 list instead. IP address of the interface. Leave empty to configure the
interface using DHCP.
''; '';
}; };
prefixLength = mkOption { prefixLength = mkOption {
default = null; default = null;
example = 24;
type = types.nullOr types.int;
description = '' description = ''
Defunct, supply the prefix length in the ip4 list instead. Subnet mask of the interface, specified as the number of
bits in the prefix (<literal>24</literal>).
''; '';
}; };
subnetMask = mkOption { subnetMask = mkOption {
default = null; default = null;
description = '' description = ''
Defunct, supply the prefix length in the ip4 list instead. Defunct, supply the prefix length instead.
''; '';
}; };
ipv6Address = mkOption { ipv6Address = mkOption {
default = null; default = null;
example = "2001:1470:fffd:2098::e006";
type = types.nullOr types.str;
description = '' description = ''
Defunct, create an address in the ip6 list instead. IPv6 address of the interface. Leave empty to configure the
interface using NDP.
''; '';
}; };
ipv6prefixLength = mkOption { ipv6prefixLength = mkOption {
default = null; default = 64;
example = 64;
type = types.int;
description = '' description = ''
Defunct, supply the prefix length in the ip6 list instead. Subnet mask of the interface, specified as the number of
bits in the prefix (<literal>64</literal>).
''; '';
}; };
@ -470,12 +482,8 @@ in
assertions = assertions =
flip map interfaces (i: { flip map interfaces (i: {
assertion = i.ipAddress == null && i.prefixLength == null && i.subnetMask == null; assertion = i.subnetMask == null;
message = "The networking.interfaces.${i.name}.ipAddress option is defunct. Use networking.ip4 instead."; message = "The networking.interfaces.${i.name}.subnetMask option is defunct. Use prefixLength instead.";
})
++ flip map interfaces (i: {
assertion = i.ipv6Address == null && i.ipv6prefixLength == null;
message = "The networking.interfaces.${i.name}.ipv6Address option is defunct. Use networking.ip6 instead.";
}); });
boot.kernelModules = [ ] boot.kernelModules = [ ]
@ -574,7 +582,18 @@ in
# network device, so it only gets started after the interface # network device, so it only gets started after the interface
# has appeared, and it's stopped when the interface # has appeared, and it's stopped when the interface
# disappears. # disappears.
configureInterface = i: nameValuePair "${i.name}-cfg" configureInterface = i:
let
ips = i.ip4 ++ optionals cfg.enableIPv6 i.ip6
++ optional (i.ipAddress != null) {
ipAddress = i.ipAddress;
prefixLength = i.prefixLength;
} ++ optional (cfg.enableIPv6 && i.ipv6Address != null) {
ipAddress = i.ipv6Address;
prefixLength = i.ipv6PrefixLength;
};
in
nameValuePair "${i.name}-cfg"
{ description = "Configuration of ${i.name}"; { description = "Configuration of ${i.name}";
wantedBy = [ "network-interfaces.target" ]; wantedBy = [ "network-interfaces.target" ];
bindsTo = [ "sys-subsystem-net-devices-${i.name}.device" ]; bindsTo = [ "sys-subsystem-net-devices-${i.name}.device" ];
@ -606,7 +625,7 @@ in
# useful when the Nix store is accessed via this # useful when the Nix store is accessed via this
# interface (e.g. in a QEMU VM test). # interface (e.g. in a QEMU VM test).
'' ''
+ flip concatMapStrings (i.ip4 ++ optionals cfg.enableIPv6 i.ip6) (ip: + flip concatMapStrings (ips) (ip:
let let
address = "${ip.address}/${toString ip.prefixLength}"; address = "${ip.address}/${toString ip.prefixLength}";
in in
@ -622,7 +641,7 @@ in
fi fi
fi fi
'') '')
+ optionalString (i.ip4 != [ ] || (cfg.enableIPv6 && i.ip6 != [ ])) + optionalString (ips != [ ])
'' ''
if [ restart_network_setup = true ]; then if [ restart_network_setup = true ]; then
# Ensure that the default gateway remains set. # Ensure that the default gateway remains set.
@ -643,7 +662,7 @@ in
'' ''
echo "releasing configured ip's..." echo "releasing configured ip's..."
'' ''
+ flip concatMapStrings (i.ip4 ++ optionals cfg.enableIPv6 i.ip6) (ip: + flip concatMapStrings (ips) (ip:
let let
address = "${ip.address}/${toString ip.prefixLength}"; address = "${ip.address}/${toString ip.prefixLength}";
in in