summary refs log tree commit diff
diff options
context:
space:
mode:
authorNikita Uvarov <uv.nikita@gmail.com>2019-01-04 22:24:13 +0100
committerNikita Uvarov <uv.nikita@gmail.com>2019-01-07 14:21:17 +0100
commit53013ead39a40e51878a76e24f94a4ae46a9b98a (patch)
treec0c4a446bcff259627cdb0f44654509d4eed1446
parent9a262a71a1e0ceae8b014aadc1de0e50dbc471b4 (diff)
downloadnixpkgs-53013ead39a40e51878a76e24f94a4ae46a9b98a.tar
nixpkgs-53013ead39a40e51878a76e24f94a4ae46a9b98a.tar.gz
nixpkgs-53013ead39a40e51878a76e24f94a4ae46a9b98a.tar.bz2
nixpkgs-53013ead39a40e51878a76e24f94a4ae46a9b98a.tar.lz
nixpkgs-53013ead39a40e51878a76e24f94a4ae46a9b98a.tar.xz
nixpkgs-53013ead39a40e51878a76e24f94a4ae46a9b98a.tar.zst
nixpkgs-53013ead39a40e51878a76e24f94a4ae46a9b98a.zip
nixos/containers: add bridge without address specified
According to systemd-nspawn(1), --network-bridge implies --network-veth,
and --port option is supported only when private networking is enabled.
Fixes #52417.
-rw-r--r--nixos/modules/virtualisation/containers.nix28
-rw-r--r--nixos/tests/containers-bridge.nix17
2 files changed, 32 insertions, 13 deletions
diff --git a/nixos/modules/virtualisation/containers.nix b/nixos/modules/virtualisation/containers.nix
index 3dd36f9b12e..f0668032282 100644
--- a/nixos/modules/virtualisation/containers.nix
+++ b/nixos/modules/virtualisation/containers.nix
@@ -36,7 +36,7 @@ let
         #! ${pkgs.runtimeShell} -e
 
         # Initialise the container side of the veth pair.
-        if [ -n "$HOST_ADDRESS" ] || [ -n "$LOCAL_ADDRESS" ]; then
+        if [ -n "$HOST_ADDRESS" ] || [ -n "$LOCAL_ADDRESS" ] || [ -n "$HOST_BRIDGE" ]; then
 
           ip link set host0 name eth0
           ip link set dev eth0 up
@@ -90,18 +90,20 @@ let
 
       if [ -n "$HOST_ADDRESS" ] || [ -n "$LOCAL_ADDRESS" ]; then
         extraFlags+=" --network-veth"
-        if [ -n "$HOST_BRIDGE" ]; then
-          extraFlags+=" --network-bridge=$HOST_BRIDGE"
-        fi
-        if [ -n "$HOST_PORT" ]; then
-          OIFS=$IFS
-          IFS=","
-          for i in $HOST_PORT
-          do
-              extraFlags+=" --port=$i"
-          done
-          IFS=$OIFS
-        fi
+      fi
+
+      if [ -n "$HOST_PORT" ]; then
+        OIFS=$IFS
+        IFS=","
+        for i in $HOST_PORT
+        do
+            extraFlags+=" --port=$i"
+        done
+        IFS=$OIFS
+      fi
+
+      if [ -n "$HOST_BRIDGE" ]; then
+        extraFlags+=" --network-bridge=$HOST_BRIDGE"
       fi
 
       extraFlags+=" ${concatStringsSep " " (mapAttrsToList nspawnExtraVethArgs cfg.extraVeths)}"
diff --git a/nixos/tests/containers-bridge.nix b/nixos/tests/containers-bridge.nix
index 777cf9a7e7f..0eae51433d2 100644
--- a/nixos/tests/containers-bridge.nix
+++ b/nixos/tests/containers-bridge.nix
@@ -45,6 +45,19 @@ import ./make-test.nix ({ pkgs, ...} : {
             };
         };
 
+      containers.web-noip =
+        {
+          autoStart = true;
+          privateNetwork = true;
+          hostBridge = "br0";
+          config =
+            { services.httpd.enable = true;
+              services.httpd.adminAddr = "foo@example.org";
+              networking.firewall.allowedTCPPorts = [ 80 ];
+            };
+        };
+
+
       virtualisation.pathsInNixDB = [ pkgs.stdenv ];
     };
 
@@ -56,6 +69,10 @@ import ./make-test.nix ({ pkgs, ...} : {
       # Start the webserver container.
       $machine->succeed("nixos-container status webserver") =~ /up/ or die;
 
+      # Check if bridges exist inside containers
+      $machine->succeed("nixos-container run webserver -- ip link show eth0");
+      $machine->succeed("nixos-container run web-noip -- ip link show eth0");
+
       "${containerIp}" =~ /([^\/]+)\/([0-9+])/;
       my $ip = $1;
       chomp $ip;