diff options
author | rnhmjoj <rnhmjoj@inventati.org> | 2017-12-03 05:13:14 +0100 |
---|---|---|
committer | rnhmjoj <rnhmjoj@inventati.org> | 2018-02-17 14:01:24 +0100 |
commit | c1bed05e341756f7fdfa73035c7f1e078e49be3d (patch) | |
tree | 462f47865c4ff0949484d0aaa2e3845d0eb2ddc7 /nixos/modules/tasks | |
parent | f41111c4da9a7eb5cade95d945eec7576757d27d (diff) | |
download | nixlib-c1bed05e341756f7fdfa73035c7f1e078e49be3d.tar nixlib-c1bed05e341756f7fdfa73035c7f1e078e49be3d.tar.gz nixlib-c1bed05e341756f7fdfa73035c7f1e078e49be3d.tar.bz2 nixlib-c1bed05e341756f7fdfa73035c7f1e078e49be3d.tar.lz nixlib-c1bed05e341756f7fdfa73035c7f1e078e49be3d.tar.xz nixlib-c1bed05e341756f7fdfa73035c7f1e078e49be3d.tar.zst nixlib-c1bed05e341756f7fdfa73035c7f1e078e49be3d.zip |
nixos/networking-interfaces: rename IP addresses/routes options
Diffstat (limited to 'nixos/modules/tasks')
-rw-r--r-- | nixos/modules/tasks/network-interfaces-scripted.nix | 12 | ||||
-rw-r--r-- | nixos/modules/tasks/network-interfaces-systemd.nix | 10 | ||||
-rw-r--r-- | nixos/modules/tasks/network-interfaces.nix | 95 |
3 files changed, 40 insertions, 77 deletions
diff --git a/nixos/modules/tasks/network-interfaces-scripted.nix b/nixos/modules/tasks/network-interfaces-scripted.nix index 28bbc27a2693..66732ce7732e 100644 --- a/nixos/modules/tasks/network-interfaces-scripted.nix +++ b/nixos/modules/tasks/network-interfaces-scripted.nix @@ -20,14 +20,8 @@ let "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 @@ -207,7 +201,7 @@ let 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}"''; diff --git a/nixos/modules/tasks/network-interfaces-systemd.nix b/nixos/modules/tasks/network-interfaces-systemd.nix index be7f52a76def..c640e886fca8 100644 --- a/nixos/modules/tasks/network-interfaces-systemd.nix +++ b/nixos/modules/tasks/network-interfaces-systemd.nix @@ -9,14 +9,8 @@ let 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"; diff --git a/nixos/modules/tasks/network-interfaces.nix b/nixos/modules/tasks/network-interfaces.nix index 6f8ee147649d..5036b701bd86 100644 --- a/nixos/modules/tasks/network-interfaces.nix +++ b/nixos/modules/tasks/network-interfaces.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, utils, stdenv, ... }: +{ config, options, lib, pkgs, utils, stdenv, ... }: with lib; with utils; @@ -182,7 +182,6 @@ let interfaceOpts = { name, ... }: { options = { - name = mkOption { example = "eth0"; type = types.str; @@ -209,7 +208,7 @@ let ''; }; - ip4 = mkOption { + ipv4.addresses = mkOption { default = [ ]; example = [ { address = "10.0.0.1"; prefixLength = 16; } @@ -221,7 +220,7 @@ let ''; }; - ip6 = mkOption { + ipv6.addresses = mkOption { default = [ ]; example = [ { address = "fdfd:b3f0:482::1"; prefixLength = 48; } @@ -233,7 +232,7 @@ let ''; }; - ipv4Routes = mkOption { + ipv4.routes = mkOption { default = []; example = [ { address = "10.0.0.0"; prefixLength = 16; } @@ -245,7 +244,7 @@ let ''; }; - ipv6Routes = mkOption { + ipv6.routes = mkOption { default = []; example = [ { address = "fdfd:b3f0::"; prefixLength = 48; } @@ -257,53 +256,6 @@ let ''; }; - 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"; @@ -375,6 +327,32 @@ let 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; }) + ]; + }; hexChars = stringToCharacters "0123456789abcdef"; @@ -511,7 +489,7 @@ in networking.interfaces = mkOption { default = {}; example = - { eth0.ip4 = [ { + { eth0.ipv4 = [ { address = "131.211.84.78"; prefixLength = 25; } ]; @@ -990,13 +968,10 @@ in 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 @@ -1005,7 +980,7 @@ in 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. ''; |