From 755c30c7a2dcd30bffab17478cc06e4c9088d62d Mon Sep 17 00:00:00 2001 From: Sander van der Burg Date: Mon, 6 Dec 2010 22:02:37 +0000 Subject: [PATCH] - nixos-deploy-network no longer uses an infrastructure model => use nixpkgs.system and deployment.hostname instead - implemented --no-out-link option so that invoking these tools from scripts leave no garbage behind - some misc. cleanups svn path=/nixos/trunk/; revision=25019 --- .../tools/nixos-build-vms/nixos-build-vms.sh | 36 +++++++------- .../tools/nixos-deploy-network/deploy.nix | 46 ++++++++---------- .../nixos-deploy-network.sh | 47 ++++++++----------- 3 files changed, 60 insertions(+), 69 deletions(-) diff --git a/modules/installer/tools/nixos-build-vms/nixos-build-vms.sh b/modules/installer/tools/nixos-build-vms/nixos-build-vms.sh index 709b9051fc45..88dfff6cec6e 100644 --- a/modules/installer/tools/nixos-build-vms/nixos-build-vms.sh +++ b/modules/installer/tools/nixos-build-vms/nixos-build-vms.sh @@ -4,18 +4,18 @@ showUsage() { - echo "Usage: $0 -n network_expr -i infrastructure_expr" + echo "Usage: $0 network_expr" echo "Options:" echo - echo "-n,--network Network Nix expression which captures properties of machines in the network" - echo "--use-backdoor Indicates that the backdoor must be enabled so that the VMs can be accessed through a UNIX domain socket" - echo "--show-trace Shows the output trace" - echo "-h,--help Shows the usage of this command" + echo "--use-backdoor Indicates that the backdoor must be enabled so that the VMs can be accessed through a UNIX domain socket" + echo "--no-out-link Do not create a 'result' symlink" + echo "--show-trace Shows the output trace" + echo "-h,--help Shows the usage of this command" } # Parse valid argument options -PARAMS=`getopt -n $0 -o n:h -l network:,use-backdoor,show-trace,help -- "$@"` +PARAMS=`getopt -n $0 -o h -l use-backdoor,show-trace,help -- "$@"` if [ $? != 0 ] then @@ -30,12 +30,12 @@ eval set -- "$PARAMS" while [ "$1" != "--" ] do case "$1" in - -n|--network) - networkExpr=`readlink -f $2` - ;; --use-backdoor) useBackdoorArg="--arg useBackdoor true" ;; + --no-out-link) + noOutLinkArg="--no-out-link" + ;; --show-trace) showTraceArg="--show-trace" ;; @@ -48,19 +48,23 @@ do shift done -# Validate the given options +shift -if [ "$networkExpr" = "" ] -then - echo "ERROR: A network expression must be specified!" >&2 - exit 1 -fi +# Validate the given options if [ -z "$NIXOS" ] then NIXOS=/etc/nixos/nixos fi +if [ "$@" = "" ] +then + echo "ERROR: A network expression must be specified!" >&2 + exit 1 +else + networkExpr=$(readlink -f $@) +fi + # Build a network of VMs -nix-build $NIXOS/modules/installer/tools/nixos-build-vms/build-vms.nix --argstr networkExpr $networkExpr --argstr nixos $NIXOS --argstr nixpkgs $NIXPKGS_ALL $useBackdoorArg $showTraceArg +nix-build $NIXOS/modules/installer/tools/nixos-build-vms/build-vms.nix --argstr networkExpr $networkExpr --argstr nixos $NIXOS --argstr nixpkgs $NIXPKGS_ALL $useBackdoorArg $noOutLinkArg $showTraceArg diff --git a/modules/installer/tools/nixos-deploy-network/deploy.nix b/modules/installer/tools/nixos-deploy-network/deploy.nix index 58d6adfefaf3..630be914d4b8 100644 --- a/modules/installer/tools/nixos-deploy-network/deploy.nix +++ b/modules/installer/tools/nixos-deploy-network/deploy.nix @@ -1,7 +1,6 @@ { nixos ? /etc/nixos/nixos , nixpkgs ? /etc/nixos/nixpkgs , networkExpr -, infrastructureExpr , targetProperty ? "hostname" }: @@ -12,19 +11,17 @@ let inherit (pkgs.lib) concatMapStrings; network = import networkExpr; - infrastructure = import infrastructureExpr; - generateRollbackSucceededPhase = network: infrastructure: configs: + generateRollbackSucceededPhase = network: configs: concatMapStrings (configurationName: let - infrastructureElement = getAttr configurationName infrastructure; config = getAttr configurationName configs; in '' if [ "$rollback" != "$succeeded" ] then - ssh $NIX_SSHOPTS ${getAttr targetProperty infrastructureElement} nix-env -p /nix/var/nix/profiles/system --rollback - ssh $NIX_SSHOPTS ${getAttr targetProperty infrastructureElement} /nix/var/nix/profiles/system/bin/switch-to-configuration switch + ssh $NIX_SSHOPTS ${getAttr targetProperty (config.deployment)} nix-env -p /nix/var/nix/profiles/system --rollback + ssh $NIX_SSHOPTS ${getAttr targetProperty (config.deployment)} /nix/var/nix/profiles/system/bin/switch-to-configuration switch rollback=$((rollback + 1)) fi @@ -32,33 +29,31 @@ let ) (attrNames network) ; - generateDistributionPhase = network: infrastructure: configs: + generateDistributionPhase = network: configs: concatMapStrings (configurationName: let - infrastructureElement = getAttr configurationName infrastructure; config = getAttr configurationName configs; in '' - echo "=== copy system closure to ${getAttr targetProperty infrastructureElement} ===" - nix-copy-closure --to ${getAttr targetProperty infrastructureElement} ${config.system.build.toplevel} + echo "=== copy system closure to ${getAttr targetProperty (config.deployment)} ===" + nix-copy-closure --to ${getAttr targetProperty (config.deployment)} ${config.system.build.toplevel} '' ) (attrNames network) ; - generateActivationPhase = network: infrastructure: configs: + generateActivationPhase = network: configs: concatMapStrings (configurationName: let - infrastructureElement = getAttr configurationName infrastructure; config = getAttr configurationName configs; in '' - echo "=== activating system configuration on ${getAttr targetProperty infrastructureElement} ===" - ssh $NIX_SSHOPTS ${getAttr targetProperty infrastructureElement} nix-env -p /nix/var/nix/profiles/system --set ${config.system.build.toplevel} || - (ssh $NIX_SSHOPTS ${getAttr targetProperty infrastructureElement} nix-env -p /nix/var/nix/profiles/system --rollback; rollbackSucceeded) + echo "=== activating system configuration on ${getAttr targetProperty (config.deployment)} ===" + ssh $NIX_SSHOPTS ${getAttr targetProperty (config.deployment)} nix-env -p /nix/var/nix/profiles/system --set ${config.system.build.toplevel} || + (ssh $NIX_SSHOPTS ${getAttr targetProperty (config.deployment)} nix-env -p /nix/var/nix/profiles/system --rollback; rollbackSucceeded) - ssh $NIX_SSHOPTS ${getAttr targetProperty infrastructureElement} /nix/var/nix/profiles/system/bin/switch-to-configuration switch || - ( ssh $NIX_SSHOPTS ${getAttr targetProperty infrastructureElement} nix-env -p /nix/var/nix/profiles/system --rollback - ssh $NIX_SSHOPTS ${getAttr targetProperty infrastructureElement} /nix/var/nix/profiles/system/bin/switch-to-configuration switch + ssh $NIX_SSHOPTS ${getAttr targetProperty (config.deployment)} /nix/var/nix/profiles/system/bin/switch-to-configuration switch || + ( ssh $NIX_SSHOPTS ${getAttr targetProperty (config.deployment)} nix-env -p /nix/var/nix/profiles/system --rollback + ssh $NIX_SSHOPTS ${getAttr targetProperty (config.deployment)} /nix/var/nix/profiles/system/bin/switch-to-configuration switch rollbackSucceeded ) @@ -67,22 +62,21 @@ let ) (attrNames network) ; - evaluateMachines = network: infrastructure: + evaluateMachines = network: listToAttrs (map (configurationName: let configuration = getAttr configurationName network; - system = (getAttr configurationName infrastructure).system; in { name = configurationName; value = (import "${nixos}/lib/eval-config.nix" { - inherit nixpkgs system; + inherit nixpkgs; modules = [ configuration ]; - extraArgs = evaluateMachines network infrastructure; + extraArgs = evaluateMachines network; }).config; } ) (attrNames (network))) ; - configs = evaluateMachines network infrastructure; + configs = evaluateMachines network; in pkgs.stdenv.mkDerivation { name = "deploy-script"; @@ -100,18 +94,18 @@ pkgs.stdenv.mkDerivation { rollbackSucceeded() { rollback=0 - ${generateRollbackSucceededPhase network infrastructure configs} + ${generateRollbackSucceededPhase network configs} } # Distribution phase - ${generateDistributionPhase network infrastructure configs} + ${generateDistributionPhase network configs} # Activation phase succeeded=0 - ${generateActivationPhase network infrastructure configs} + ${generateActivationPhase network configs} EOF chmod +x $out/bin/deploy-systems ''; diff --git a/modules/installer/tools/nixos-deploy-network/nixos-deploy-network.sh b/modules/installer/tools/nixos-deploy-network/nixos-deploy-network.sh index 08370a15dc86..dc2b2198cfc7 100644 --- a/modules/installer/tools/nixos-deploy-network/nixos-deploy-network.sh +++ b/modules/installer/tools/nixos-deploy-network/nixos-deploy-network.sh @@ -4,18 +4,17 @@ showUsage() { - echo "Usage: $0 -n network_expr -i infrastructure_expr" + echo "Usage: $0 network_expr" echo "Options:" echo - echo "-n,--network Network Nix expression which captures properties of machines in the network" - echo "-i,--infrastructure Infrastructure Nix expression which captures properties of machines in the network" - echo "--show-trace Shows an output trace" - echo "-h,--help Shows the usage of this command" + echo "--show-trace Shows an output trace" + echo "--no-out-link Do not create a 'result' symlink" + echo "-h,--help Shows the usage of this command" } # Parse valid argument options -PARAMS=`getopt -n $0 -o n:i:h -l network:,infrastructure:,show-trace,help -- "$@"` +PARAMS=`getopt -n $0 -o h -l show-trace,no-out-link,help -- "$@"` if [ $? != 0 ] then @@ -30,15 +29,12 @@ eval set -- "$PARAMS" while [ "$1" != "--" ] do case "$1" in - -n|--network) - networkExpr=`readlink -f $2` - ;; - -i|--infrastructure) - infrastructureExpr=`readlink -f $2` - ;; --show-trace) showTraceArg="--show-trace" ;; + --no-out-link) + noOutLinkArg="--no-out-link" + ;; -h|--help) showUsage exit 0 @@ -48,27 +44,24 @@ do shift done +shift + # Validate the given options -if [ "$infrastructureExpr" = "" ] -then - echo "ERROR: A infrastructure expression must be specified!" >&2 - exit 1 -fi - -if [ "$networkExpr" = "" ] -then - echo "ERROR: A network expression must be specified!" >&2 - exit 1 -fi - if [ -z "$NIXOS" ] then NIXOS=/etc/nixos/nixos fi +if [ "$@" = "" ] +then + echo "ERROR: A network Nix expression must be specified!" >&2 + exit 1 +else + networkExpr=$(readlink -f $@) +fi + # Deploy the network -nix-build $NIXOS/modules/installer/tools/nixos-deploy-network/deploy.nix --argstr networkExpr $networkExpr --argstr infrastructureExpr $infrastructureExpr $showTraceArg -./result/bin/deploy-systems -rm -f result +vms=`nix-build $NIXOS/modules/installer/tools/nixos-deploy-network/deploy.nix --argstr networkExpr $networkExpr $showTraceArg $noOutLinkArg` +$vms/bin/deploy-systems