Skip to content

Commit

Permalink
Merge pull request #49392 from uvNikita/nixos/containers/veths
Browse files Browse the repository at this point in the history
nixos/containers: don't create veths if not configured
  • Loading branch information
Mic92 committed Dec 3, 2018
2 parents 41af4a5 + 6d4b02d commit 958d8e6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions nixos/modules/virtualisation/containers.nix
Expand Up @@ -36,7 +36,7 @@ let
#! ${pkgs.runtimeShell} -e
# Initialise the container side of the veth pair.
if [ "$PRIVATE_NETWORK" = 1 ]; then
if [ -n "$HOST_ADDRESS" ] || [ -n "$LOCAL_ADDRESS" ]; then
ip link set host0 name eth0
ip link set dev eth0 up
Expand Down Expand Up @@ -85,6 +85,10 @@ let
cp --remove-destination /etc/resolv.conf "$root/etc/resolv.conf"
if [ "$PRIVATE_NETWORK" = 1 ]; then
extraFlags+=" --private-network"
fi
if [ -n "$HOST_ADDRESS" ] || [ -n "$LOCAL_ADDRESS" ]; then
extraFlags+=" --network-veth"
if [ -n "$HOST_BRIDGE" ]; then
extraFlags+=" --network-bridge=$HOST_BRIDGE"
Expand Down Expand Up @@ -153,7 +157,7 @@ let
# Clean up existing machined registration and interfaces.
machinectl terminate "$INSTANCE" 2> /dev/null || true
if [ "$PRIVATE_NETWORK" = 1 ]; then
if [ -n "$HOST_ADDRESS" ] || [ -n "$LOCAL_ADDRESS" ]; then
ip link del dev "ve-$INSTANCE" 2> /dev/null || true
ip link del dev "vb-$INSTANCE" 2> /dev/null || true
fi
Expand Down Expand Up @@ -200,7 +204,7 @@ let
'';
in
''
if [ "$PRIVATE_NETWORK" = 1 ]; then
if [ -n "$HOST_ADDRESS" ] || [ -n "$LOCAL_ADDRESS" ]; then
if [ -z "$HOST_BRIDGE" ]; then
ifaceHost=ve-$INSTANCE
ip link set dev $ifaceHost up
Expand Down Expand Up @@ -352,7 +356,7 @@ let
List of forwarded ports from host to container. Each forwarded port
is specified by protocol, hostPort and containerPort. By default,
protocol is tcp and hostPort and containerPort are assumed to be
the same if containerPort is not explicitly given.
the same if containerPort is not explicitly given.
'';
};

Expand Down Expand Up @@ -699,7 +703,7 @@ in
# container so that container@.target can get the container
# configuration.
environment.etc =
let mkPortStr = p: p.protocol + ":" + (toString p.hostPort) + ":" + (if p.containerPort == null then toString p.hostPort else toString p.containerPort);
let mkPortStr = p: p.protocol + ":" + (toString p.hostPort) + ":" + (if p.containerPort == null then toString p.hostPort else toString p.containerPort);
in mapAttrs' (name: cfg: nameValuePair "containers/${name}.conf"
{ text =
''
Expand Down

0 comments on commit 958d8e6

Please sign in to comment.