From 0cca0f477f168cee994b2c90d20b713f2bb67d85 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 19 Mar 2014 10:15:57 +0100 Subject: nixos-container-shell -> nixos-container { login | root-shell } --- nixos/modules/virtualisation/containers.nix | 60 ++++--------------------- nixos/modules/virtualisation/nixos-container.sh | 54 ++++++++++++++++++++++ 2 files changed, 62 insertions(+), 52 deletions(-) create mode 100644 nixos/modules/virtualisation/nixos-container.sh diff --git a/nixos/modules/virtualisation/containers.nix b/nixos/modules/virtualisation/containers.nix index cdd9e729dc16..e718398815d2 100644 --- a/nixos/modules/virtualisation/containers.nix +++ b/nixos/modules/virtualisation/containers.nix @@ -14,57 +14,13 @@ let installPhase = "true"; }; - nixos-container-shell = pkgs.writeScriptBin "nixos-container-shell" - '' - #! ${pkgs.bash}/bin/sh -e - - usage() { - echo "Usage: $0 " >&2 - echo " $0 (-r|--root-shell) " >&2 - } - - args="`getopt --options 'r' -l help -- "$@"`" - eval "set -- $args" - rootShell= - while [ $# -gt 0 ]; do - case "$1" in - (--help) usage; exit 0;; - (-r|--root-shell) rootShell=1;; - (--) shift; break;; - (*) break;; - esac - shift - done - - container="$1" - if [ -z "$container" ]; then - usage - exit 1 - fi - shift - - root="/var/lib/containers/$container" - if ! [ -d "$root" ]; then - echo "$0: container ‘$container’ does not exist" >&2 - exit 1 - fi - - if [ -n "$rootShell" ]; then - socket="$root/var/lib/root-shell.socket" - else - socket="$root/var/lib/login.socket" - fi - if ! [ -S "$socket" ]; then - echo "$0: socket ‘$socket’ does not exist" >&2 - exit 1 - fi - - if [ -n "$rootShell" ]; then - exec ${pkgs.socat}/bin/socat "unix:$socket" - - else - exec ${pkgs.socat}/bin/socat "unix:$socket" -,echo=0,raw - fi - ''; + nixos-container = pkgs.substituteAll { + name = "nixos-container"; + dir = "bin"; + isExecutable = true; + src = ./nixos-container.sh; + inherit (pkgs) bash socat; + }; in @@ -299,7 +255,7 @@ in ${cfg.localAddress} ${name}.containers '') config.containers); - environment.systemPackages = optional (config.containers != {}) nixos-container-shell; + environment.systemPackages = optional (config.containers != {}) nixos-container; }; } diff --git a/nixos/modules/virtualisation/nixos-container.sh b/nixos/modules/virtualisation/nixos-container.sh new file mode 100644 index 000000000000..f4e34588d6eb --- /dev/null +++ b/nixos/modules/virtualisation/nixos-container.sh @@ -0,0 +1,54 @@ +#! @bash@/bin/sh -e + +usage() { + echo "Usage: $0 login " >&2 + echo " $0 root-shell " >&2 +} + +args="`getopt --options '' -l help -- "$@"`" +eval "set -- $args" +while [ $# -gt 0 ]; do + case "$1" in + (--help) usage; exit 0;; + (--) shift; break;; + (*) break;; + esac + shift +done + +action="$1" +if [ -z "$action" ]; then usage; exit 1; fi +shift + +getContainerRoot() { + root="/var/lib/containers/$container" + if ! [ -d "$root" ]; then + echo "$0: container ‘$container’ does not exist" >&2 + exit 1 + fi +} + +if [ $action = login ]; then + + container="$1" + if [ -z "$container" ]; then usage; exit 1; fi + shift + + getContainerRoot + + exec @socat@/bin/socat "unix:$root/var/lib/login.socket" -,echo=0,raw + +elif [ $action = root-shell ]; then + + container="$1" + if [ -z "$container" ]; then usage; exit 1; fi + shift + + getContainerRoot + + exec @socat@/bin/socat "unix:$root/var/lib/root-shell.socket" - + +else + echo "$0: unknown action ‘$action’" >&2 + exit 1 +fi -- cgit 1.4.1