From 0bfc631de20a351b23af571e80347df1a58a298a Mon Sep 17 00:00:00 2001 From: Ian-Woo Kim Date: Sun, 4 Dec 2016 04:00:07 +0000 Subject: nixos-container: support multiple port forwarding. change type of hostPort from 'string' to 'listOf str' --- nixos/modules/virtualisation/containers.nix | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'nixos/modules/virtualisation') diff --git a/nixos/modules/virtualisation/containers.nix b/nixos/modules/virtualisation/containers.nix index 88273545c2b6..83b7a2fdecdd 100644 --- a/nixos/modules/virtualisation/containers.nix +++ b/nixos/modules/virtualisation/containers.nix @@ -90,7 +90,13 @@ let extraFlags+=" --network-bridge=$HOST_BRIDGE" fi if [ -n "$HOST_PORT" ]; then - extraFlags+=" --port=$HOST_PORT" + OIFS=$IFS + IFS="," + for i in $HOST_PORT + do + extraFlags+=" --port=$i" + done + IFS=$OIFS fi fi @@ -320,11 +326,11 @@ let }; hostPort = mkOption { - type = types.nullOr types.string; + type = types.listOf types.str; default = null; - example = "8080"; + example = [ "8080" ]; description = '' - Allow port forwarding from the host to the container. + List of forwarded ports from the host to the container. ''; }; @@ -665,8 +671,8 @@ in ${optionalString (cfg.hostBridge != null) '' HOST_BRIDGE=${cfg.hostBridge} ''} - ${optionalString (cfg.hostPort != null) '' - HOST_PORT=${cfg.hostPort} + ${optionalString (length cfg.hostPort > 0) '' + HOST_PORT=${concatStringsSep "," cfg.hostPort} ''} ${optionalString (cfg.hostAddress != null) '' HOST_ADDRESS=${cfg.hostAddress} -- cgit 1.4.1