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.
This commit is contained in:
parent
9a262a71a1
commit
53013ead39
|
@ -36,7 +36,7 @@ let
|
||||||
#! ${pkgs.runtimeShell} -e
|
#! ${pkgs.runtimeShell} -e
|
||||||
|
|
||||||
# Initialise the container side of the veth pair.
|
# 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 host0 name eth0
|
||||||
ip link set dev eth0 up
|
ip link set dev eth0 up
|
||||||
|
@ -90,9 +90,8 @@ let
|
||||||
|
|
||||||
if [ -n "$HOST_ADDRESS" ] || [ -n "$LOCAL_ADDRESS" ]; then
|
if [ -n "$HOST_ADDRESS" ] || [ -n "$LOCAL_ADDRESS" ]; then
|
||||||
extraFlags+=" --network-veth"
|
extraFlags+=" --network-veth"
|
||||||
if [ -n "$HOST_BRIDGE" ]; then
|
|
||||||
extraFlags+=" --network-bridge=$HOST_BRIDGE"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$HOST_PORT" ]; then
|
if [ -n "$HOST_PORT" ]; then
|
||||||
OIFS=$IFS
|
OIFS=$IFS
|
||||||
IFS=","
|
IFS=","
|
||||||
|
@ -102,6 +101,9 @@ let
|
||||||
done
|
done
|
||||||
IFS=$OIFS
|
IFS=$OIFS
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -n "$HOST_BRIDGE" ]; then
|
||||||
|
extraFlags+=" --network-bridge=$HOST_BRIDGE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
extraFlags+=" ${concatStringsSep " " (mapAttrsToList nspawnExtraVethArgs cfg.extraVeths)}"
|
extraFlags+=" ${concatStringsSep " " (mapAttrsToList nspawnExtraVethArgs cfg.extraVeths)}"
|
||||||
|
|
|
@ -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 ];
|
virtualisation.pathsInNixDB = [ pkgs.stdenv ];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,6 +69,10 @@ import ./make-test.nix ({ pkgs, ...} : {
|
||||||
# Start the webserver container.
|
# Start the webserver container.
|
||||||
$machine->succeed("nixos-container status webserver") =~ /up/ or die;
|
$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+])/;
|
"${containerIp}" =~ /([^\/]+)\/([0-9+])/;
|
||||||
my $ip = $1;
|
my $ip = $1;
|
||||||
chomp $ip;
|
chomp $ip;
|
||||||
|
|
Loading…
Reference in a new issue