nixos/networking-interfaces: rename IP addresses/routes options

rnhmjoj c1bed05e f41111c4

Changed files
+72 -111
nixos
+1 -1
nixos/doc/manual/configuration/ipv4-config.xml
···
follows:
<programlisting>
-
networking.interfaces.eth0.ip4 = [ { address = "192.168.1.2"; prefixLength = 24; } ];
+
networking.interfaces.eth0.ipv4.addresses = [ { address = "192.168.1.2"; prefixLength = 24; } ];
</programlisting>
Typically you’ll also want to set a default gateway and set of name
+1 -1
nixos/doc/manual/configuration/ipv6-config.xml
···
DHCPv6. You can configure an interface manually:
<programlisting>
-
networking.interfaces.eth0.ip6 = [ { address = "fe00:aa:bb:cc::2"; prefixLength = 64; } ];
+
networking.interfaces.eth0.ipv6.addresses = [ { address = "fe00:aa:bb:cc::2"; prefixLength = 64; } ];
</programlisting>
</para>
+2 -2
nixos/lib/build-vms.nix
···
let
interfacesNumbered = zipLists config.virtualisation.vlans (range 1 255);
interfaces = flip map interfacesNumbered ({ fst, snd }:
-
nameValuePair "eth${toString snd}" { ip4 =
+
nameValuePair "eth${toString snd}" { ipv4.addresses =
[ { address = "192.168.${toString fst}.${toString m.snd}";
prefixLength = 24;
} ];
···
networking.interfaces = listToAttrs interfaces;
networking.primaryIPAddress =
-
optionalString (interfaces != []) (head (head interfaces).value.ip4).address;
+
optionalString (interfaces != []) (head (head interfaces).value.ipv4.addresses).address;
# Put the IP addresses of all VMs in this machine's
# /etc/hosts file. If a machine has multiple
+1 -1
nixos/modules/services/networking/dhcpcd.nix
···
# Don't start dhcpcd on explicitly configured interfaces or on
# interfaces that are part of a bridge, bond or sit device.
ignoredInterfaces =
-
map (i: i.name) (filter (i: if i.useDHCP != null then !i.useDHCP else i.ip4 != [ ] || i.ipAddress != null) interfaces)
+
map (i: i.name) (filter (i: if i.useDHCP != null then !i.useDHCP else i.ipv4.addresses != [ ]) interfaces)
++ 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.vswitches))
+3 -9
nixos/modules/tasks/network-interfaces-scripted.nix
···
"sys-subsystem-net-devices-${escapeSystemdPath interface}.device";
interfaceIps = i:
-
i.ip4 ++ optionals cfg.enableIPv6 i.ip6
-
++ optional (i.ipAddress != null) {
-
address = i.ipAddress;
-
prefixLength = i.prefixLength;
-
} ++ optional (cfg.enableIPv6 && i.ipv6Address != null) {
-
address = i.ipv6Address;
-
prefixLength = i.ipv6PrefixLength;
-
};
+
i.ipv4.addresses
+
++ optionals cfg.enableIPv6 i.ipv6.addresses;
destroyBond = i: ''
while true; do
···
state="/run/nixos/network/routes/${i.name}"
mkdir -p $(dirname "$state")
-
${flip concatMapStrings (i.ipv4Routes ++ i.ipv6Routes) (route:
+
${flip concatMapStrings (i.ipv4.routes ++ i.ipv6.routes) (route:
let
cidr = "${route.address}/${toString route.prefixLength}";
via = optionalString (route.via != null) ''via "${route.via}"'';
+2 -8
nixos/modules/tasks/network-interfaces-systemd.nix
···
interfaces = attrValues cfg.interfaces;
interfaceIps = i:
-
i.ip4 ++ optionals cfg.enableIPv6 i.ip6
-
++ optional (i.ipAddress != null) {
-
address = i.ipAddress;
-
prefixLength = i.prefixLength;
-
} ++ optional (cfg.enableIPv6 && i.ipv6Address != null) {
-
address = i.ipv6Address;
-
prefixLength = i.ipv6PrefixLength;
-
};
+
i.ipv4.addresses
+
++ optionals cfg.enableIPv6 i.ipv6.addresses;
dhcpStr = useDHCP: if useDHCP == true || useDHCP == null then "both" else "none";
+35 -60
nixos/modules/tasks/network-interfaces.nix
···
-
{ config, lib, pkgs, utils, stdenv, ... }:
+
{ config, options, lib, pkgs, utils, stdenv, ... }:
with lib;
with utils;
···
interfaceOpts = { name, ... }: {
options = {
-
name = mkOption {
example = "eth0";
type = types.str;
···
'';
};
-
ip4 = mkOption {
+
ipv4.addresses = mkOption {
default = [ ];
example = [
{ address = "10.0.0.1"; prefixLength = 16; }
···
'';
};
-
ip6 = mkOption {
+
ipv6.addresses = mkOption {
default = [ ];
example = [
{ address = "fdfd:b3f0:482::1"; prefixLength = 48; }
···
'';
};
-
ipv4Routes = mkOption {
+
ipv4.routes = mkOption {
default = [];
example = [
{ address = "10.0.0.0"; prefixLength = 16; }
···
'';
};
-
ipv6Routes = mkOption {
+
ipv6.routes = mkOption {
default = [];
example = [
{ address = "fdfd:b3f0::"; prefixLength = 48; }
···
'';
};
-
ipAddress = mkOption {
-
default = null;
-
example = "10.0.0.1";
-
type = types.nullOr types.str;
-
description = ''
-
IP address of the interface. Leave empty to configure the
-
interface using DHCP.
-
'';
-
};
-
-
prefixLength = mkOption {
-
default = null;
-
example = 24;
-
type = types.nullOr types.int;
-
description = ''
-
Subnet mask of the interface, specified as the number of
-
bits in the prefix (<literal>24</literal>).
-
'';
-
};
-
-
subnetMask = mkOption {
-
default = null;
-
description = ''
-
Defunct, supply the prefix length instead.
-
'';
-
};
-
-
ipv6Address = mkOption {
-
default = null;
-
example = "2001:1470:fffd:2098::e006";
-
type = types.nullOr types.str;
-
description = ''
-
IPv6 address of the interface. Leave empty to configure the
-
interface using NDP.
-
'';
-
};
-
-
ipv6PrefixLength = mkOption {
-
default = 64;
-
example = 64;
-
type = types.int;
-
description = ''
-
Subnet mask of the interface, specified as the number of
-
bits in the prefix (<literal>64</literal>).
-
'';
-
};
-
macAddress = mkOption {
default = null;
example = "00:11:22:33:44:55";
···
config = {
name = mkDefault name;
};
+
+
# Renamed or removed options
+
imports =
+
let
+
defined = x: x != "_mkMergedOptionModule";
+
in [
+
(mkRenamedOptionModule [ "ip4" ] [ "ipv4" "addresses"])
+
(mkRenamedOptionModule [ "ip6" ] [ "ipv6" "addresses"])
+
(mkRemovedOptionModule [ "subnetMask" ] ''
+
Supply a prefix length instead; use option
+
networking.interfaces.<name>.ipv{4,6}.addresses'')
+
(mkMergedOptionModule
+
[ [ "ipAddress" ] [ "prefixLength" ] ]
+
[ "ipv4" "addresses" ]
+
(cfg: with cfg;
+
optional (defined ipAddress && defined prefixLength)
+
{ address = ipAddress; prefixLength = prefixLength; }))
+
(mkMergedOptionModule
+
[ [ "ipv6Address" ] [ "ipv6PrefixLength" ] ]
+
[ "ipv6" "addresses" ]
+
(cfg: with cfg;
+
optional (defined ipv6Address && defined ipv6PrefixLength)
+
{ address = ipv6Address; prefixLength = ipv6PrefixLength; }))
+
+
({ options.warnings = options.warnings; })
+
];
};
···
networking.interfaces = mkOption {
default = {};
example =
-
{ eth0.ip4 = [ {
+
{ eth0.ipv4 = [ {
address = "131.211.84.78";
prefixLength = 25;
} ];
···
config = {
+
warnings = concatMap (i: i.warnings) interfaces;
+
assertions =
(flip map interfaces (i: {
-
assertion = i.subnetMask == null;
-
message = ''
-
The networking.interfaces."${i.name}".subnetMask option is defunct. Use prefixLength instead.
-
'';
-
})) ++ (flip map interfaces (i: {
# With the linux kernel, interface name length is limited by IFNAMSIZ
# to 16 bytes, including the trailing null byte.
# See include/linux/if.h in the kernel sources
···
The name of networking.interfaces."${i.name}" is too long, it needs to be less than 16 characters.
'';
})) ++ (flip map slaveIfs (i: {
-
assertion = i.ip4 == [ ] && i.ipAddress == null && i.ip6 == [ ] && i.ipv6Address == null;
+
assertion = i.ipv4.addresses == [ ] && i.ipv6.addresses == [ ];
message = ''
The networking.interfaces."${i.name}" must not have any defined ips when it is a slave.
'';
+27 -29
nixos/tests/networking.nix
···
firewall.allowedUDPPorts = [ 547 ];
interfaces = mkOverride 0 (listToAttrs (flip map vlanIfs (n:
nameValuePair "eth${toString n}" {
-
ipAddress = "192.168.${toString n}.1";
-
prefixLength = 24;
-
ipv6Address = "fd00:1234:5678:${toString n}::1";
-
ipv6PrefixLength = 64;
+
ipv4.addresses = [ { address = "192.168.${toString n}.1"; prefixLength = 24;} ];
+
ipv6.addresses = [ { address = "fd00:1234:5678:${toString n}::1"; prefixLength = 64;} ];
})));
};
services.dhcpd4 = {
···
firewall.allowPing = true;
useDHCP = false;
defaultGateway = "192.168.1.1";
-
interfaces.eth1.ip4 = mkOverride 0 [
+
interfaces.eth1.ipv4.addresses = mkOverride 0 [
{ address = "192.168.1.2"; prefixLength = 24; }
{ address = "192.168.1.3"; prefixLength = 32; }
{ address = "192.168.1.10"; prefixLength = 32; }
];
-
interfaces.eth2.ip4 = mkOverride 0 [
+
interfaces.eth2.ipv4.addresses = mkOverride 0 [
{ address = "192.168.2.2"; prefixLength = 24; }
];
};
···
firewall.allowPing = true;
useDHCP = true;
interfaces.eth1 = {
-
ip4 = mkOverride 0 [ ];
-
ip6 = mkOverride 0 [ ];
+
ipv4.addresses = mkOverride 0 [ ];
+
ipv6.addresses = mkOverride 0 [ ];
};
interfaces.eth2 = {
-
ip4 = mkOverride 0 [ ];
-
ip6 = mkOverride 0 [ ];
+
ipv4.addresses = mkOverride 0 [ ];
+
ipv6.addresses = mkOverride 0 [ ];
};
};
};
···
firewall.allowPing = true;
useDHCP = false;
interfaces.eth1 = {
-
ip4 = mkOverride 0 [ ];
+
ipv4.addresses = mkOverride 0 [ ];
useDHCP = true;
};
-
interfaces.eth2.ip4 = mkOverride 0 [ ];
+
interfaces.eth2.ipv4.addresses = mkOverride 0 [ ];
};
};
testScript = { nodes, ... }:
···
interfaces = [ "eth1" "eth2" ];
driverOptions.mode = "balance-rr";
};
-
interfaces.eth1.ip4 = mkOverride 0 [ ];
-
interfaces.eth2.ip4 = mkOverride 0 [ ];
-
interfaces.bond.ip4 = mkOverride 0
+
interfaces.eth1.ipv4.addresses = mkOverride 0 [ ];
+
interfaces.eth2.ipv4.addresses = mkOverride 0 [ ];
+
interfaces.bond.ipv4.addresses = mkOverride 0
[ { inherit address; prefixLength = 30; } ];
};
};
···
useNetworkd = networkd;
firewall.allowPing = true;
useDHCP = false;
-
interfaces.eth1.ip4 = mkOverride 0
+
interfaces.eth1.ipv4.addresses = mkOverride 0
[ { inherit address; prefixLength = 24; } ];
};
};
···
firewall.allowPing = true;
useDHCP = false;
bridges.bridge.interfaces = [ "eth1" "eth2" ];
-
interfaces.eth1.ip4 = mkOverride 0 [ ];
-
interfaces.eth2.ip4 = mkOverride 0 [ ];
-
interfaces.bridge.ip4 = mkOverride 0
+
interfaces.eth1.ipv4.addresses = mkOverride 0 [ ];
+
interfaces.eth2.ipv4.addresses = mkOverride 0 [ ];
+
interfaces.bridge.ipv4.addresses = mkOverride 0
[ { address = "192.168.1.1"; prefixLength = 24; } ];
};
};
···
firewall.allowPing = true;
useDHCP = true;
macvlans.macvlan.interface = "eth1";
-
interfaces.eth1.ip4 = mkOverride 0 [ ];
+
interfaces.eth1.ipv4.addresses = mkOverride 0 [ ];
};
};
testScript = { nodes, ... }:
···
local = address4;
dev = "eth1";
};
-
interfaces.eth1.ip4 = mkOverride 0
+
interfaces.eth1.ipv4.addresses = mkOverride 0
[ { address = address4; prefixLength = 24; } ];
-
interfaces.sit.ip6 = mkOverride 0
+
interfaces.sit.ipv6.addresses = mkOverride 0
[ { address = address6; prefixLength = 64; } ];
};
};
···
id = 1;
interface = "eth0";
};
-
interfaces.eth0.ip4 = mkOverride 0 [ ];
-
interfaces.eth1.ip4 = mkOverride 0 [ ];
-
interfaces.vlan.ip4 = mkOverride 0
+
interfaces.eth0.ipv4.addresses = mkOverride 0 [ ];
+
interfaces.eth1.ipv4.addresses = mkOverride 0 [ ];
+
interfaces.vlan.ipv4.addresses = mkOverride 0
[ { inherit address; prefixLength = 24; } ];
};
};
···
machine = {
networking.useDHCP = false;
networking.interfaces."eth0" = {
-
ip4 = [ { address = "192.168.1.2"; prefixLength = 24; } ];
-
ip6 = [ { address = "2001:1470:fffd:2097::"; prefixLength = 64; } ];
-
ipv6Routes = [
+
ipv4.addresses = [ { address = "192.168.1.2"; prefixLength = 24; } ];
+
ipv6.addresses = [ { address = "2001:1470:fffd:2097::"; prefixLength = 64; } ];
+
ipv6.routes = [
{ address = "fdfd:b3f0::"; prefixLength = 48; }
{ address = "2001:1470:fffd:2098::"; prefixLength = 64; via = "fdfd:b3f0::1"; }
];
-
ipv4Routes = [
+
ipv4.routes = [
{ address = "10.0.0.0"; prefixLength = 16; options = { mtu = "1500"; }; }
{ address = "192.168.2.0"; prefixLength = 24; via = "192.168.1.1"; }
];