nixos/networkd: reformat code with a single option per line

Simplifies greatly the interpretation of commit differences.
This commit is contained in:
datafoo 2020-06-30 10:13:37 +02:00
parent b51835d247
commit 1f0371c650

View File

@ -10,11 +10,29 @@ let
checkLink = checkUnitConfig "Link" [ checkLink = checkUnitConfig "Link" [
(assertOnlyFields [ (assertOnlyFields [
"Description" "Alias" "MACAddressPolicy" "MACAddress" "NamePolicy" "Name" "OriginalName" "Description"
"MTUBytes" "BitsPerSecond" "Duplex" "AutoNegotiation" "WakeOnLan" "Port" "Advertise" "Alias"
"TCPSegmentationOffload" "TCP6SegmentationOffload" "GenericSegmentationOffload" "MACAddressPolicy"
"GenericReceiveOffload" "LargeReceiveOffload" "RxChannels" "TxChannels" "MACAddress"
"OtherChannels" "CombinedChannels" "NamePolicy"
"Name"
"OriginalName"
"MTUBytes"
"BitsPerSecond"
"Duplex"
"AutoNegotiation"
"WakeOnLan"
"Port"
"Advertise"
"TCPSegmentationOffload"
"TCP6SegmentationOffload"
"GenericSegmentationOffload"
"GenericReceiveOffload"
"LargeReceiveOffload"
"RxChannels"
"TxChannels"
"OtherChannels"
"CombinedChannels"
]) ])
(assertValueOneOf "MACAddressPolicy" ["persistent" "random" "none"]) (assertValueOneOf "MACAddressPolicy" ["persistent" "random" "none"])
(assertMacAddress "MACAddress") (assertMacAddress "MACAddress")
@ -42,21 +60,51 @@ let
checkNetdev = checkUnitConfig "Netdev" [ checkNetdev = checkUnitConfig "Netdev" [
(assertOnlyFields [ (assertOnlyFields [
"Description" "Name" "Kind" "MTUBytes" "MACAddress" "Description"
"Name"
"Kind"
"MTUBytes"
"MACAddress"
]) ])
(assertHasField "Name") (assertHasField "Name")
(assertHasField "Kind") (assertHasField "Kind")
(assertValueOneOf "Kind" [ (assertValueOneOf "Kind" [
"bond" "bridge" "dummy" "gre" "gretap" "ip6gre" "ip6tnl" "ip6gretap" "ipip" "bond"
"ipvlan" "macvlan" "macvtap" "sit" "tap" "tun" "veth" "vlan" "vti" "vti6" "bridge"
"vxlan" "geneve" "vrf" "vcan" "vxcan" "wireguard" "netdevsim" "xfrm" "dummy"
"gre"
"gretap"
"ip6gre"
"ip6tnl"
"ip6gretap"
"ipip"
"ipvlan"
"macvlan"
"macvtap"
"sit"
"tap"
"tun"
"veth"
"vlan"
"vti"
"vti6"
"vxlan"
"geneve"
"vrf"
"vcan"
"vxcan"
"wireguard"
"netdevsim"
"xfrm"
]) ])
(assertByteFormat "MTUBytes") (assertByteFormat "MTUBytes")
(assertMacAddress "MACAddress") (assertMacAddress "MACAddress")
]; ];
checkVRF = checkUnitConfig "VRF" [ checkVRF = checkUnitConfig "VRF" [
(assertOnlyFields [ "Table" ]) (assertOnlyFields [
"Table"
])
(assertMinimum "Table" 0) (assertMinimum "Table" 0)
]; ];
@ -65,7 +113,9 @@ let
# refrain ourselves from providing a footgun. # refrain ourselves from providing a footgun.
checkWireGuard = checkUnitConfig "WireGuard" [ checkWireGuard = checkUnitConfig "WireGuard" [
(assertOnlyFields [ (assertOnlyFields [
"PrivateKeyFile" "ListenPort" "FwMark" "PrivateKeyFile"
"ListenPort"
"FwMark"
]) ])
# The following check won't work on nix <= 2.2 # The following check won't work on nix <= 2.2
# see https://github.com/NixOS/nix/pull/2378 # see https://github.com/NixOS/nix/pull/2378
@ -80,14 +130,23 @@ let
# refrain ourselves from providing a footgun. # refrain ourselves from providing a footgun.
checkWireGuardPeer = checkUnitConfig "WireGuardPeer" [ checkWireGuardPeer = checkUnitConfig "WireGuardPeer" [
(assertOnlyFields [ (assertOnlyFields [
"PublicKey" "PresharedKeyFile" "AllowedIPs" "PublicKey"
"Endpoint" "PersistentKeepalive" "PresharedKeyFile"
"AllowedIPs"
"Endpoint"
"PersistentKeepalive"
]) ])
(assertRange "PersistentKeepalive" 1 65535) (assertRange "PersistentKeepalive" 1 65535)
]; ];
checkVlan = checkUnitConfig "VLAN" [ checkVlan = checkUnitConfig "VLAN" [
(assertOnlyFields ["Id" "GVRP" "MVRP" "LooseBinding" "ReorderHeader"]) (assertOnlyFields [
"Id"
"GVRP"
"MVRP"
"LooseBinding"
"ReorderHeader"
])
(assertRange "Id" 0 4094) (assertRange "Id" 0 4094)
(assertValueOneOf "GVRP" boolValues) (assertValueOneOf "GVRP" boolValues)
(assertValueOneOf "MVRP" boolValues) (assertValueOneOf "MVRP" boolValues)
@ -96,17 +155,34 @@ let
]; ];
checkMacvlan = checkUnitConfig "MACVLAN" [ checkMacvlan = checkUnitConfig "MACVLAN" [
(assertOnlyFields ["Mode"]) (assertOnlyFields [
"Mode"
])
(assertValueOneOf "Mode" ["private" "vepa" "bridge" "passthru"]) (assertValueOneOf "Mode" ["private" "vepa" "bridge" "passthru"])
]; ];
checkVxlan = checkUnitConfig "VXLAN" [ checkVxlan = checkUnitConfig "VXLAN" [
(assertOnlyFields [ (assertOnlyFields [
"Id" "Remote" "Local" "TOS" "TTL" "MacLearning" "FDBAgeingSec" "Id"
"MaximumFDBEntries" "ReduceARPProxy" "L2MissNotification" "Remote"
"L3MissNotification" "RouteShortCircuit" "UDPChecksum" "Local"
"UDP6ZeroChecksumTx" "UDP6ZeroChecksumRx" "RemoteChecksumTx" "TOS"
"RemoteChecksumRx" "GroupPolicyExtension" "DestinationPort" "PortRange" "TTL"
"MacLearning"
"FDBAgeingSec"
"MaximumFDBEntries"
"ReduceARPProxy"
"L2MissNotification"
"L3MissNotification"
"RouteShortCircuit"
"UDPChecksum"
"UDP6ZeroChecksumTx"
"UDP6ZeroChecksumRx"
"RemoteChecksumTx"
"RemoteChecksumRx"
"GroupPolicyExtension"
"DestinationPort"
"PortRange"
"FlowLabel" "FlowLabel"
]) ])
(assertRange "TTL" 0 255) (assertRange "TTL" 0 255)
@ -126,8 +202,19 @@ let
checkTunnel = checkUnitConfig "Tunnel" [ checkTunnel = checkUnitConfig "Tunnel" [
(assertOnlyFields [ (assertOnlyFields [
"Local" "Remote" "TOS" "TTL" "DiscoverPathMTU" "IPv6FlowLabel" "CopyDSCP" "Local"
"EncapsulationLimit" "Key" "InputKey" "OutputKey" "Mode" "Independent" "Remote"
"TOS"
"TTL"
"DiscoverPathMTU"
"IPv6FlowLabel"
"CopyDSCP"
"EncapsulationLimit"
"Key"
"InputKey"
"OutputKey"
"Mode"
"Independent"
"AllowLocalRemote" "AllowLocalRemote"
]) ])
(assertRange "TTL" 0 255) (assertRange "TTL" 0 255)
@ -139,12 +226,22 @@ let
]; ];
checkPeer = checkUnitConfig "Peer" [ checkPeer = checkUnitConfig "Peer" [
(assertOnlyFields ["Name" "MACAddress"]) (assertOnlyFields [
"Name"
"MACAddress"
])
(assertMacAddress "MACAddress") (assertMacAddress "MACAddress")
]; ];
tunTapChecks = [ tunTapChecks = [
(assertOnlyFields ["OneQueue" "MultiQueue" "PacketInfo" "VNetHeader" "User" "Group"]) (assertOnlyFields [
"OneQueue"
"MultiQueue"
"PacketInfo"
"VNetHeader"
"User"
"Group"
])
(assertValueOneOf "OneQueue" boolValues) (assertValueOneOf "OneQueue" boolValues)
(assertValueOneOf "MultiQueue" boolValues) (assertValueOneOf "MultiQueue" boolValues)
(assertValueOneOf "PacketInfo" boolValues) (assertValueOneOf "PacketInfo" boolValues)
@ -157,18 +254,41 @@ let
checkBond = checkUnitConfig "Bond" [ checkBond = checkUnitConfig "Bond" [
(assertOnlyFields [ (assertOnlyFields [
"Mode" "TransmitHashPolicy" "LACPTransmitRate" "MIIMonitorSec" "Mode"
"UpDelaySec" "DownDelaySec" "LearnPacketIntervalSec" "AdSelect" "TransmitHashPolicy"
"FailOverMACPolicy" "ARPValidate" "ARPIntervalSec" "ARPIPTargets" "LACPTransmitRate"
"ARPAllTargets" "PrimaryReselectPolicy" "ResendIGMP" "PacketsPerSlave" "MIIMonitorSec"
"GratuitousARP" "AllSlavesActive" "MinLinks" "UpDelaySec"
"DownDelaySec"
"LearnPacketIntervalSec"
"AdSelect"
"FailOverMACPolicy"
"ARPValidate"
"ARPIntervalSec"
"ARPIPTargets"
"ARPAllTargets"
"PrimaryReselectPolicy"
"ResendIGMP"
"PacketsPerSlave"
"GratuitousARP"
"AllSlavesActive"
"MinLinks"
]) ])
(assertValueOneOf "Mode" [ (assertValueOneOf "Mode" [
"balance-rr" "active-backup" "balance-xor" "balance-rr"
"broadcast" "802.3ad" "balance-tlb" "balance-alb" "active-backup"
"balance-xor"
"broadcast"
"802.3ad"
"balance-tlb"
"balance-alb"
]) ])
(assertValueOneOf "TransmitHashPolicy" [ (assertValueOneOf "TransmitHashPolicy" [
"layer2" "layer3+4" "layer2+3" "encap2+3" "encap3+4" "layer2"
"layer3+4"
"layer2+3"
"encap2+3"
"encap3+4"
]) ])
(assertValueOneOf "LACPTransmitRate" ["slow" "fast"]) (assertValueOneOf "LACPTransmitRate" ["slow" "fast"])
(assertValueOneOf "AdSelect" ["stable" "bandwidth" "count"]) (assertValueOneOf "AdSelect" ["stable" "bandwidth" "count"])
@ -184,7 +304,8 @@ let
checkXfrm = checkUnitConfig "Xfrm" [ checkXfrm = checkUnitConfig "Xfrm" [
(assertOnlyFields [ (assertOnlyFields [
"InterfaceId" "Independent" "InterfaceId"
"Independent"
]) ])
# The following check won't work on nix <= 2.2 # The following check won't work on nix <= 2.2
# see https://github.com/NixOS/nix/pull/2378 # see https://github.com/NixOS/nix/pull/2378
@ -197,15 +318,49 @@ let
checkNetwork = checkUnitConfig "Network" [ checkNetwork = checkUnitConfig "Network" [
(assertOnlyFields [ (assertOnlyFields [
"Description" "DHCP" "DHCPServer" "LinkLocalAddressing" "IPv4LLRoute" "Description"
"IPv6Token" "LLMNR" "MulticastDNS" "DNSOverTLS" "DNSSEC" "DHCP"
"DNSSECNegativeTrustAnchors" "LLDP" "EmitLLDP" "BindCarrier" "Address" "DHCPServer"
"Gateway" "DNS" "Domains" "NTP" "IPForward" "IPMasquerade" "LinkLocalAddressing"
"IPv6PrivacyExtensions" "IPv6AcceptRA" "IPv6DuplicateAddressDetection" "IPv4LLRoute"
"IPv6HopLimit" "IPv4ProxyARP" "IPv6ProxyNDP" "IPv6ProxyNDPAddress" "IPv6Token"
"IPv6PrefixDelegation" "IPv6MTUBytes" "Bridge" "Bond" "VRF" "VLAN" "LLMNR"
"IPVLAN" "MACVLAN" "VXLAN" "Tunnel" "ActiveSlave" "PrimarySlave" "MulticastDNS"
"ConfigureWithoutCarrier" "Xfrm" "KeepConfiguration" "DNSOverTLS"
"DNSSEC"
"DNSSECNegativeTrustAnchors"
"LLDP"
"EmitLLDP"
"BindCarrier"
"Address"
"Gateway"
"DNS"
"Domains"
"NTP"
"IPForward"
"IPMasquerade"
"IPv6PrivacyExtensions"
"IPv6AcceptRA"
"IPv6DuplicateAddressDetection"
"IPv6HopLimit"
"IPv4ProxyARP"
"IPv6ProxyNDP"
"IPv6ProxyNDPAddress"
"IPv6PrefixDelegation"
"IPv6MTUBytes"
"Bridge"
"Bond"
"VRF"
"VLAN"
"IPVLAN"
"MACVLAN"
"VXLAN"
"Tunnel"
"ActiveSlave"
"PrimarySlave"
"ConfigureWithoutCarrier"
"Xfrm"
"KeepConfiguration"
]) ])
# Note: For DHCP the values both, none, v4, v6 are deprecated # Note: For DHCP the values both, none, v4, v6 are deprecated
(assertValueOneOf "DHCP" ["yes" "no" "ipv4" "ipv6" "both" "none" "v4" "v6"]) (assertValueOneOf "DHCP" ["yes" "no" "ipv4" "ipv6" "both" "none" "v4" "v6"])
@ -233,9 +388,17 @@ let
checkAddress = checkUnitConfig "Address" [ checkAddress = checkUnitConfig "Address" [
(assertOnlyFields [ (assertOnlyFields [
"Address" "Peer" "Broadcast" "Label" "PreferredLifetime" "Scope" "Address"
"HomeAddress" "DuplicateAddressDetection" "ManageTemporaryAddress" "Peer"
"PrefixRoute" "AutoJoin" "Broadcast"
"Label"
"PreferredLifetime"
"Scope"
"HomeAddress"
"DuplicateAddressDetection"
"ManageTemporaryAddress"
"PrefixRoute"
"AutoJoin"
]) ])
(assertHasField "Address") (assertHasField "Address")
(assertValueOneOf "PreferredLifetime" ["forever" "infinity" "0" 0]) (assertValueOneOf "PreferredLifetime" ["forever" "infinity" "0" 0])
@ -248,9 +411,19 @@ let
checkRoutingPolicyRule = checkUnitConfig "RoutingPolicyRule" [ checkRoutingPolicyRule = checkUnitConfig "RoutingPolicyRule" [
(assertOnlyFields [ (assertOnlyFields [
"TypeOfService" "From" "To" "FirewallMark" "Table" "Priority" "TypeOfService"
"IncomingInterface" "OutgoingInterface" "SourcePort" "DestinationPort" "From"
"IPProtocol" "InvertRule" "Family" "To"
"FirewallMark"
"Table"
"Priority"
"IncomingInterface"
"OutgoingInterface"
"SourcePort"
"DestinationPort"
"IPProtocol"
"InvertRule"
"Family"
]) ])
(assertRange "TypeOfService" 0 255) (assertRange "TypeOfService" 0 255)
# The following check won't work on nix <= 2.2 # The following check won't work on nix <= 2.2
@ -268,20 +441,49 @@ let
checkRoute = checkUnitConfig "Route" [ checkRoute = checkUnitConfig "Route" [
(assertOnlyFields [ (assertOnlyFields [
"Gateway" "GatewayOnLink" "Destination" "Source" "Metric" "Gateway"
"IPv6Preference" "Scope" "PreferredSource" "Table" "Protocol" "Type" "GatewayOnLink"
"InitialCongestionWindow" "InitialAdvertisedReceiveWindow" "QuickAck" "Destination"
"Source"
"Metric"
"IPv6Preference"
"Scope"
"PreferredSource"
"Table"
"Protocol"
"Type"
"InitialCongestionWindow"
"InitialAdvertisedReceiveWindow"
"QuickAck"
"MTUBytes" "MTUBytes"
]) ])
]; ];
checkDhcpV4 = checkUnitConfig "DHCPv4" [ checkDhcpV4 = checkUnitConfig "DHCPv4" [
(assertOnlyFields [ (assertOnlyFields [
"UseDNS" "RoutesToDNS" "UseNTP" "UseMTU" "Anonymize" "SendHostname" "UseHostname" "UseDNS"
"Hostname" "UseDomains" "UseRoutes" "UseTimezone" "RoutesToDNS"
"ClientIdentifier" "VendorClassIdentifier" "UserClass" "MaxAttempts" "UseNTP"
"DUIDType" "DUIDRawData" "IAID" "RequestBroadcast" "RouteMetric" "RouteTable" "UseMTU"
"ListenPort" "SendRelease" "Anonymize"
"SendHostname"
"UseHostname"
"Hostname"
"UseDomains"
"UseRoutes"
"UseTimezone"
"ClientIdentifier"
"VendorClassIdentifier"
"UserClass"
"MaxAttempts"
"DUIDType"
"DUIDRawData"
"IAID"
"RequestBroadcast"
"RouteMetric"
"RouteTable"
"ListenPort"
"SendRelease"
]) ])
(assertValueOneOf "UseDNS" boolValues) (assertValueOneOf "UseDNS" boolValues)
(assertValueOneOf "RoutesToDNS" boolValues) (assertValueOneOf "RoutesToDNS" boolValues)
@ -302,7 +504,10 @@ let
checkDhcpV6 = checkUnitConfig "DHCPv6" [ checkDhcpV6 = checkUnitConfig "DHCPv6" [
(assertOnlyFields [ (assertOnlyFields [
"UseDNS" "UseNTP" "RapidCommit" "ForceDHCPv6PDOtherInformation" "UseDNS"
"UseNTP"
"RapidCommit"
"ForceDHCPv6PDOtherInformation"
"PrefixDelegationHint" "PrefixDelegationHint"
]) ])
(assertValueOneOf "UseDNS" boolValues) (assertValueOneOf "UseDNS" boolValues)
@ -313,8 +518,14 @@ let
checkIpv6PrefixDelegation = checkUnitConfig "IPv6PrefixDelegation" [ checkIpv6PrefixDelegation = checkUnitConfig "IPv6PrefixDelegation" [
(assertOnlyFields [ (assertOnlyFields [
"Managed" "OtherInformation" "RouterLifetimeSec" "Managed"
"RouterPreference" "EmitDNS" "DNS" "EmitDomains" "Domains" "OtherInformation"
"RouterLifetimeSec"
"RouterPreference"
"EmitDNS"
"DNS"
"EmitDomains"
"Domains"
"DNSLifetimeSec" "DNSLifetimeSec"
]) ])
(assertValueOneOf "Managed" boolValues) (assertValueOneOf "Managed" boolValues)
@ -327,8 +538,11 @@ let
checkIpv6Prefix = checkUnitConfig "IPv6Prefix" [ checkIpv6Prefix = checkUnitConfig "IPv6Prefix" [
(assertOnlyFields [ (assertOnlyFields [
"AddressAutoconfiguration" "OnLink" "Prefix" "AddressAutoconfiguration"
"PreferredLifetimeSec" "ValidLifetimeSec" "OnLink"
"Prefix"
"PreferredLifetimeSec"
"ValidLifetimeSec"
]) ])
(assertValueOneOf "AddressAutoconfiguration" boolValues) (assertValueOneOf "AddressAutoconfiguration" boolValues)
(assertValueOneOf "OnLink" boolValues) (assertValueOneOf "OnLink" boolValues)
@ -339,8 +553,17 @@ let
checkDhcpServer = checkUnitConfig "DHCPServer" [ checkDhcpServer = checkUnitConfig "DHCPServer" [
(assertOnlyFields [ (assertOnlyFields [
"PoolOffset" "PoolSize" "DefaultLeaseTimeSec" "MaxLeaseTimeSec" "PoolOffset"
"EmitDNS" "DNS" "EmitNTP" "NTP" "EmitRouter" "EmitTimezone" "Timezone" "PoolSize"
"DefaultLeaseTimeSec"
"MaxLeaseTimeSec"
"EmitDNS"
"DNS"
"EmitNTP"
"NTP"
"EmitRouter"
"EmitTimezone"
"Timezone"
]) ])
(assertValueOneOf "EmitDNS" boolValues) (assertValueOneOf "EmitDNS" boolValues)
(assertValueOneOf "EmitNTP" boolValues) (assertValueOneOf "EmitNTP" boolValues)
@ -351,14 +574,28 @@ let
# .network files have a [Link] section with different options than in .netlink files # .network files have a [Link] section with different options than in .netlink files
checkNetworkLink = checkUnitConfig "Link" [ checkNetworkLink = checkUnitConfig "Link" [
(assertOnlyFields [ (assertOnlyFields [
"MACAddress" "MTUBytes" "ARP" "Multicast" "Unmanaged" "RequiredForOnline" "MACAddress"
"MTUBytes"
"ARP"
"Multicast"
"Unmanaged"
"RequiredForOnline"
]) ])
(assertMacAddress "MACAddress") (assertMacAddress "MACAddress")
(assertByteFormat "MTUBytes") (assertByteFormat "MTUBytes")
(assertValueOneOf "ARP" boolValues) (assertValueOneOf "ARP" boolValues)
(assertValueOneOf "Multicast" boolValues) (assertValueOneOf "Multicast" boolValues)
(assertValueOneOf "Unmanaged" boolValues) (assertValueOneOf "Unmanaged" boolValues)
(assertValueOneOf "RequiredForOnline" (boolValues ++ ["off" "no-carrier" "dormant" "degraded-carrier" "carrier" "degraded" "enslaved" "routable"])) (assertValueOneOf "RequiredForOnline" (boolValues ++ [
"off"
"no-carrier"
"dormant"
"degraded-carrier"
"carrier"
"degraded"
"enslaved"
"routable"
]))
]; ];