···476476 '';
477477 };
478478479479+ macvlans = mkOption {
480480+ type = types.listOf types.str;
481481+ default = [];
482482+ example = [ "eth1" "eth2" ];
483483+ description = ''
484484+ The list of host interfaces from which macvlans will be
485485+ created. For each interface specified, a macvlan interface
486486+ will be created and moved to the container.
487487+ '';
488488+ };
489489+479490 extraVeths = mkOption {
480491 type = with types; attrsOf (submodule { options = networkOptions; });
481492 default = {};
···654665 ''}
655666 ''}
656667 INTERFACES="${toString cfg.interfaces}"
668668+ MACVLANS="${toString cfg.macvlans}"
657669 ${optionalString cfg.autoStart ''
658670 AUTO_START=1
659671 ''}
+82
nixos/tests/containers-macvlans.nix
···11+# Test for NixOS' container support.
22+33+let
44+ # containers IP on VLAN 1
55+ containerIp1 = "192.168.1.253";
66+ containerIp2 = "192.168.1.254";
77+in
88+99+import ./make-test.nix ({ pkgs, ...} : {
1010+ name = "containers-macvlans";
1111+ meta = with pkgs.stdenv.lib.maintainers; {
1212+ maintainers = [ montag451 ];
1313+ };
1414+1515+ nodes = {
1616+1717+ machine1 =
1818+ { config, pkgs, lib, ... }:
1919+ {
2020+ virtualisation.memorySize = 256;
2121+ virtualisation.vlans = [ 1 ];
2222+2323+ # To be able to ping containers from the host, it is necessary
2424+ # to create a macvlan on the host on the VLAN 1 network.
2525+ networking.macvlans.mv-eth1-host = {
2626+ interface = "eth1";
2727+ mode = "bridge";
2828+ };
2929+ networking.interfaces.eth1.ip4 = lib.mkForce [];
3030+ networking.interfaces.mv-eth1-host = {
3131+ ip4 = [ { address = "192.168.1.1"; prefixLength = 24; } ];
3232+ };
3333+3434+ containers.test1 = {
3535+ autoStart = true;
3636+ macvlans = [ "eth1" ];
3737+3838+ config = {
3939+ networking.interfaces.mv-eth1 = {
4040+ ip4 = [ { address = containerIp1; prefixLength = 24; } ];
4141+ };
4242+ };
4343+ };
4444+4545+ containers.test2 = {
4646+ autoStart = true;
4747+ macvlans = [ "eth1" ];
4848+4949+ config = {
5050+ networking.interfaces.mv-eth1 = {
5151+ ip4 = [ { address = containerIp2; prefixLength = 24; } ];
5252+ };
5353+ };
5454+ };
5555+ };
5656+5757+ machine2 =
5858+ { config, pkgs, ... }:
5959+ {
6060+ virtualisation.memorySize = 256;
6161+ virtualisation.vlans = [ 1 ];
6262+ };
6363+6464+ };
6565+6666+ testScript = ''
6767+ startAll;
6868+ $machine1->waitForUnit("default.target");
6969+ $machine2->waitForUnit("default.target");
7070+7171+ # Ping between containers to check that macvlans are created in bridge mode
7272+ $machine1->succeed("nixos-container run test1 -- ping -n -c 1 ${containerIp2}");
7373+7474+ # Ping containers from the host (machine1)
7575+ $machine1->succeed("ping -n -c 1 ${containerIp1}");
7676+ $machine1->succeed("ping -n -c 1 ${containerIp2}");
7777+7878+ # Ping containers from the second machine to check that containers are reachable from the outside
7979+ $machine2->succeed("ping -n -c 1 ${containerIp1}");
8080+ $machine2->succeed("ping -n -c 1 ${containerIp2}");
8181+ '';
8282+})