···12follows:
1314<programlisting>
15-networking.interfaces.eth0.ip4 = [ { address = "192.168.1.2"; prefixLength = 24; } ];
16</programlisting>
1718Typically you’ll also want to set a default gateway and set of name
···12follows:
1314<programlisting>
15+networking.interfaces.eth0.ipv4.addresses = [ { address = "192.168.1.2"; prefixLength = 24; } ];
16</programlisting>
1718Typically you’ll also want to set a default gateway and set of name
+1-1
nixos/doc/manual/configuration/ipv6-config.xml
···26DHCPv6. You can configure an interface manually:
2728<programlisting>
29-networking.interfaces.eth0.ip6 = [ { address = "fe00:aa:bb:cc::2"; prefixLength = 64; } ];
30</programlisting>
31</para>
32
···26DHCPv6. You can configure an interface manually:
2728<programlisting>
29+networking.interfaces.eth0.ipv6.addresses = [ { address = "fe00:aa:bb:cc::2"; prefixLength = 64; } ];
30</programlisting>
31</para>
32
+36-4
nixos/doc/manual/release-notes/rl-1803.xml
···261 </listitem>
262 <listitem>
263 <para>
264- The option <option>services.xserver.desktopManager.default</option> is now <literal>none</literal> by default.
265- An assertion failure is thrown if WM's and DM's default are <literal>none</literal>.
266- To explicitly run a plain X session without and DM or WM, the newly introduced option <option>services.xserver.plainX</option>
267- must be set to true.
00000000000000000000000000000000268 </para>
269 </listitem>
270 <listitem>
···261 </listitem>
262 <listitem>
263 <para>
264+ In the module <option>networking.interfaces.<name></option> the
265+ following options have been removed:
266+ <itemizedlist>
267+ <listitem>
268+ <para><option>ipAddress</option></para>
269+ </listitem>
270+ <listitem>
271+ <para><option>ipv6Address</option></para>
272+ </listitem>
273+ <listitem>
274+ <para><option>prefixLength</option></para>
275+ </listitem>
276+ <listitem>
277+ <para><option>ipv6PrefixLength</option></para>
278+ </listitem>
279+ <listitem>
280+ <para><option>subnetMask</option></para>
281+ </listitem>
282+ </itemizedlist>
283+ To assign static addresses to an interface the options
284+ <option>ipv4.addresses</option> and <option>ipv6.addresses</option>
285+ should be used instead.
286+ The options <option>ip4</option> and <option>ip6</option> have been
287+ renamed to <option>ipv4.addresses</option> <option>ipv6.addresses</option>
288+ respectively.
289+ The new options <option>ipv4.routes</option> and <option>ipv6.routes</option>
290+ have been added to set up static routing.
291+ </para>
292+ </listitem>
293+ <listitem>
294+ <para>
295+ The option <option>services.xserver.desktopManager.default</option> is now
296+ <literal>none</literal> by default. An assertion failure is thrown if WM's
297+ and DM's default are <literal>none</literal>.
298+ To explicitly run a plain X session without and DM or WM, the newly
299+ introduced option <option>services.xserver.plainX</option> must be set to true.
300 </para>
301 </listitem>
302 <listitem>
+2-2
nixos/lib/build-vms.nix
···51 let
52 interfacesNumbered = zipLists config.virtualisation.vlans (range 1 255);
53 interfaces = flip map interfacesNumbered ({ fst, snd }:
54- nameValuePair "eth${toString snd}" { ip4 =
55 [ { address = "192.168.${toString fst}.${toString m.snd}";
56 prefixLength = 24;
57 } ];
···64 networking.interfaces = listToAttrs interfaces;
6566 networking.primaryIPAddress =
67- optionalString (interfaces != []) (head (head interfaces).value.ip4).address;
6869 # Put the IP addresses of all VMs in this machine's
70 # /etc/hosts file. If a machine has multiple
···51 let
52 interfacesNumbered = zipLists config.virtualisation.vlans (range 1 255);
53 interfaces = flip map interfacesNumbered ({ fst, snd }:
54+ nameValuePair "eth${toString snd}" { ipv4.addresses =
55 [ { address = "192.168.${toString fst}.${toString m.snd}";
56 prefixLength = 24;
57 } ];
···64 networking.interfaces = listToAttrs interfaces;
6566 networking.primaryIPAddress =
67+ optionalString (interfaces != []) (head (head interfaces).value.ipv4.addresses).address;
6869 # Put the IP addresses of all VMs in this machine's
70 # /etc/hosts file. If a machine has multiple
+1-1
nixos/modules/services/networking/dhcpcd.nix
···16 # Don't start dhcpcd on explicitly configured interfaces or on
17 # interfaces that are part of a bridge, bond or sit device.
18 ignoredInterfaces =
19- map (i: i.name) (filter (i: if i.useDHCP != null then !i.useDHCP else i.ip4 != [ ] || i.ipAddress != null) interfaces)
20 ++ mapAttrsToList (i: _: i) config.networking.sits
21 ++ concatLists (attrValues (mapAttrs (n: v: v.interfaces) config.networking.bridges))
22 ++ concatLists (attrValues (mapAttrs (n: v: v.interfaces) config.networking.vswitches))
···16 # Don't start dhcpcd on explicitly configured interfaces or on
17 # interfaces that are part of a bridge, bond or sit device.
18 ignoredInterfaces =
19+ map (i: i.name) (filter (i: if i.useDHCP != null then !i.useDHCP else i.ipv4.addresses != [ ]) interfaces)
20 ++ mapAttrsToList (i: _: i) config.networking.sits
21 ++ concatLists (attrValues (mapAttrs (n: v: v.interfaces) config.networking.bridges))
22 ++ concatLists (attrValues (mapAttrs (n: v: v.interfaces) config.networking.vswitches))
···1-{ config, lib, pkgs, utils, stdenv, ... }:
23with lib;
4with utils;
···101 address = mkOption {
102 type = types.str;
103 description = ''
104- IPv${toString v} address of the interface. Leave empty to configure the
105 interface using DHCP.
106 '';
107 };
···116 };
117 };
1180000000000000000000000000000000000119 gatewayCoerce = address: { inherit address; };
120121 gatewayOpts = { ... }: {
···148 interfaceOpts = { name, ... }: {
149150 options = {
151-152 name = mkOption {
153 example = "eth0";
154 type = types.str;
···175 '';
176 };
177178- ip4 = mkOption {
179 default = [ ];
180 example = [
181 { address = "10.0.0.1"; prefixLength = 16; }
···187 '';
188 };
189190- ip6 = mkOption {
191 default = [ ];
192 example = [
193 { address = "fdfd:b3f0:482::1"; prefixLength = 48; }
···199 '';
200 };
201202- ipAddress = mkOption {
203- default = null;
204- example = "10.0.0.1";
205- type = types.nullOr types.str;
206- description = ''
207- IP address of the interface. Leave empty to configure the
208- interface using DHCP.
209- '';
210- };
211-212- prefixLength = mkOption {
213- default = null;
214- example = 24;
215- type = types.nullOr types.int;
216- description = ''
217- Subnet mask of the interface, specified as the number of
218- bits in the prefix (<literal>24</literal>).
219- '';
220- };
221-222- subnetMask = mkOption {
223- default = null;
224- description = ''
225- Defunct, supply the prefix length instead.
226- '';
227- };
228-229- ipv6Address = mkOption {
230- default = null;
231- example = "2001:1470:fffd:2098::e006";
232- type = types.nullOr types.str;
233 description = ''
234- IPv6 address of the interface. Leave empty to configure the
235- interface using NDP.
236 '';
237 };
238239- ipv6PrefixLength = mkOption {
240- default = 64;
241- example = 64;
242- type = types.int;
000243 description = ''
244- Subnet mask of the interface, specified as the number of
245- bits in the prefix (<literal>64</literal>).
246 '';
247 };
248···316 config = {
317 name = mkDefault name;
318 };
00000000000000000000000000319320 };
321···453 networking.interfaces = mkOption {
454 default = {};
455 example =
456- { eth0.ip4 = [ {
457 address = "131.211.84.78";
458 prefixLength = 25;
459 } ];
···932933 config = {
93400935 assertions =
936 (flip map interfaces (i: {
937- assertion = i.subnetMask == null;
938- message = ''
939- The networking.interfaces."${i.name}".subnetMask option is defunct. Use prefixLength instead.
940- '';
941- })) ++ (flip map interfaces (i: {
942 # With the linux kernel, interface name length is limited by IFNAMSIZ
943 # to 16 bytes, including the trailing null byte.
944 # See include/linux/if.h in the kernel sources
···947 The name of networking.interfaces."${i.name}" is too long, it needs to be less than 16 characters.
948 '';
949 })) ++ (flip map slaveIfs (i: {
950- assertion = i.ip4 == [ ] && i.ipAddress == null && i.ip6 == [ ] && i.ipv6Address == null;
951 message = ''
952 The networking.interfaces."${i.name}" must not have any defined ips when it is a slave.
953 '';
···1089 '' + optionalString (i.mtu != null) ''
1090 echo "setting MTU to ${toString i.mtu}..."
1091 ip link set "${i.name}" mtu "${toString i.mtu}"
0001092 '';
1093 })));
1094
···1+{ config, options, lib, pkgs, utils, stdenv, ... }:
23with lib;
4with utils;
···101 address = mkOption {
102 type = types.str;
103 description = ''
104+ IPv${toString v} address of the interface. Leave empty to configure the
105 interface using DHCP.
106 '';
107 };
···116 };
117 };
118119+ routeOpts = v:
120+ { options = {
121+ address = mkOption {
122+ type = types.str;
123+ description = "IPv${toString v} address of the network.";
124+ };
125+126+ prefixLength = mkOption {
127+ type = types.addCheck types.int (n: n >= 0 && n <= (if v == 4 then 32 else 128));
128+ description = ''
129+ Subnet mask of the network, specified as the number of
130+ bits in the prefix (<literal>${if v == 4 then "24" else "64"}</literal>).
131+ '';
132+ };
133+134+ via = mkOption {
135+ type = types.nullOr types.str;
136+ default = null;
137+ description = "IPv${toString v} address of the next hop.";
138+ };
139+140+ options = mkOption {
141+ type = types.attrsOf types.str;
142+ default = { };
143+ example = { mtu = "1492"; window = "524288"; };
144+ description = ''
145+ Other route options. See the symbol <literal>OPTION</literal>
146+ in the <literal>ip-route(8)</literal> manual page for the details.
147+ '';
148+ };
149+150+ };
151+ };
152+153 gatewayCoerce = address: { inherit address; };
154155 gatewayOpts = { ... }: {
···182 interfaceOpts = { name, ... }: {
183184 options = {
0185 name = mkOption {
186 example = "eth0";
187 type = types.str;
···208 '';
209 };
210211+ ipv4.addresses = mkOption {
212 default = [ ];
213 example = [
214 { address = "10.0.0.1"; prefixLength = 16; }
···220 '';
221 };
222223+ ipv6.addresses = mkOption {
224 default = [ ];
225 example = [
226 { address = "fdfd:b3f0:482::1"; prefixLength = 48; }
···232 '';
233 };
234235+ ipv4.routes = mkOption {
236+ default = [];
237+ example = [
238+ { address = "10.0.0.0"; prefixLength = 16; }
239+ { address = "192.168.2.0"; prefixLength = 24; via = "192.168.1.1"; }
240+ ];
241+ type = with types; listOf (submodule (routeOpts 4));
000000000000000000000000242 description = ''
243+ List of extra IPv4 static routes that will be assigned to the interface.
0244 '';
245 };
246247+ ipv6.routes = mkOption {
248+ default = [];
249+ example = [
250+ { address = "fdfd:b3f0::"; prefixLength = 48; }
251+ { address = "2001:1470:fffd:2098::"; prefixLength = 64; via = "fdfd:b3f0::1"; }
252+ ];
253+ type = with types; listOf (submodule (routeOpts 6));
254 description = ''
255+ List of extra IPv6 static routes that will be assigned to the interface.
0256 '';
257 };
258···326 config = {
327 name = mkDefault name;
328 };
329+330+ # Renamed or removed options
331+ imports =
332+ let
333+ defined = x: x != "_mkMergedOptionModule";
334+ in [
335+ (mkRenamedOptionModule [ "ip4" ] [ "ipv4" "addresses"])
336+ (mkRenamedOptionModule [ "ip6" ] [ "ipv6" "addresses"])
337+ (mkRemovedOptionModule [ "subnetMask" ] ''
338+ Supply a prefix length instead; use option
339+ networking.interfaces.<name>.ipv{4,6}.addresses'')
340+ (mkMergedOptionModule
341+ [ [ "ipAddress" ] [ "prefixLength" ] ]
342+ [ "ipv4" "addresses" ]
343+ (cfg: with cfg;
344+ optional (defined ipAddress && defined prefixLength)
345+ { address = ipAddress; prefixLength = prefixLength; }))
346+ (mkMergedOptionModule
347+ [ [ "ipv6Address" ] [ "ipv6PrefixLength" ] ]
348+ [ "ipv6" "addresses" ]
349+ (cfg: with cfg;
350+ optional (defined ipv6Address && defined ipv6PrefixLength)
351+ { address = ipv6Address; prefixLength = ipv6PrefixLength; }))
352+353+ ({ options.warnings = options.warnings; })
354+ ];
355356 };
357···489 networking.interfaces = mkOption {
490 default = {};
491 example =
492+ { eth0.ipv4 = [ {
493 address = "131.211.84.78";
494 prefixLength = 25;
495 } ];
···968969 config = {
970971+ warnings = concatMap (i: i.warnings) interfaces;
972+973 assertions =
974 (flip map interfaces (i: {
00000975 # With the linux kernel, interface name length is limited by IFNAMSIZ
976 # to 16 bytes, including the trailing null byte.
977 # See include/linux/if.h in the kernel sources
···980 The name of networking.interfaces."${i.name}" is too long, it needs to be less than 16 characters.
981 '';
982 })) ++ (flip map slaveIfs (i: {
983+ assertion = i.ipv4.addresses == [ ] && i.ipv6.addresses == [ ];
984 message = ''
985 The networking.interfaces."${i.name}" must not have any defined ips when it is a slave.
986 '';
···1122 '' + optionalString (i.mtu != null) ''
1123 echo "setting MTU to ${toString i.mtu}..."
1124 ip link set "${i.name}" mtu "${toString i.mtu}"
1125+ '' + ''
1126+ echo -n "bringing up interface... "
1127+ ip link set "${i.name}" up && echo "done" || (echo "failed"; exit 1)
1128 '';
1129 })));
1130
+1-1
nixos/modules/virtualisation/virtualbox-host.nix
···124 '';
125 };
126127- networking.interfaces.vboxnet0.ip4 = [ { address = "192.168.56.1"; prefixLength = 24; } ];
128 # Make sure NetworkManager won't assume this interface being up
129 # means we have internet access.
130 networking.networkmanager.unmanaged = ["vboxnet0"];
···124 '';
125 };
126127+ networking.interfaces.vboxnet0.ipv4.addresses = { address = "192.168.56.1"; prefixLength = 24; };
128 # Make sure NetworkManager won't assume this interface being up
129 # means we have internet access.
130 networking.networkmanager.unmanaged = ["vboxnet0"];