- 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
This commit is contained in:
parent
796b48c367
commit
755c30c7a2
@ -4,18 +4,18 @@
|
|||||||
|
|
||||||
showUsage()
|
showUsage()
|
||||||
{
|
{
|
||||||
echo "Usage: $0 -n network_expr -i infrastructure_expr"
|
echo "Usage: $0 network_expr"
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo
|
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 "--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 "--show-trace Shows the output trace"
|
||||||
echo "-h,--help Shows the usage of this command"
|
echo "-h,--help Shows the usage of this command"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Parse valid argument options
|
# 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 ]
|
if [ $? != 0 ]
|
||||||
then
|
then
|
||||||
@ -30,12 +30,12 @@ eval set -- "$PARAMS"
|
|||||||
while [ "$1" != "--" ]
|
while [ "$1" != "--" ]
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-n|--network)
|
|
||||||
networkExpr=`readlink -f $2`
|
|
||||||
;;
|
|
||||||
--use-backdoor)
|
--use-backdoor)
|
||||||
useBackdoorArg="--arg useBackdoor true"
|
useBackdoorArg="--arg useBackdoor true"
|
||||||
;;
|
;;
|
||||||
|
--no-out-link)
|
||||||
|
noOutLinkArg="--no-out-link"
|
||||||
|
;;
|
||||||
--show-trace)
|
--show-trace)
|
||||||
showTraceArg="--show-trace"
|
showTraceArg="--show-trace"
|
||||||
;;
|
;;
|
||||||
@ -48,19 +48,23 @@ do
|
|||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
# Validate the given options
|
shift
|
||||||
|
|
||||||
if [ "$networkExpr" = "" ]
|
# Validate the given options
|
||||||
then
|
|
||||||
echo "ERROR: A network expression must be specified!" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$NIXOS" ]
|
if [ -z "$NIXOS" ]
|
||||||
then
|
then
|
||||||
NIXOS=/etc/nixos/nixos
|
NIXOS=/etc/nixos/nixos
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$@" = "" ]
|
||||||
|
then
|
||||||
|
echo "ERROR: A network expression must be specified!" >&2
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
networkExpr=$(readlink -f $@)
|
||||||
|
fi
|
||||||
|
|
||||||
# Build a network of VMs
|
# 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
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
{ nixos ? /etc/nixos/nixos
|
{ nixos ? /etc/nixos/nixos
|
||||||
, nixpkgs ? /etc/nixos/nixpkgs
|
, nixpkgs ? /etc/nixos/nixpkgs
|
||||||
, networkExpr
|
, networkExpr
|
||||||
, infrastructureExpr
|
|
||||||
, targetProperty ? "hostname"
|
, targetProperty ? "hostname"
|
||||||
}:
|
}:
|
||||||
|
|
||||||
@ -12,19 +11,17 @@ let
|
|||||||
inherit (pkgs.lib) concatMapStrings;
|
inherit (pkgs.lib) concatMapStrings;
|
||||||
|
|
||||||
network = import networkExpr;
|
network = import networkExpr;
|
||||||
infrastructure = import infrastructureExpr;
|
|
||||||
|
|
||||||
generateRollbackSucceededPhase = network: infrastructure: configs:
|
generateRollbackSucceededPhase = network: configs:
|
||||||
concatMapStrings (configurationName:
|
concatMapStrings (configurationName:
|
||||||
let
|
let
|
||||||
infrastructureElement = getAttr configurationName infrastructure;
|
|
||||||
config = getAttr configurationName configs;
|
config = getAttr configurationName configs;
|
||||||
in
|
in
|
||||||
''
|
''
|
||||||
if [ "$rollback" != "$succeeded" ]
|
if [ "$rollback" != "$succeeded" ]
|
||||||
then
|
then
|
||||||
ssh $NIX_SSHOPTS ${getAttr targetProperty infrastructureElement} nix-env -p /nix/var/nix/profiles/system --rollback
|
ssh $NIX_SSHOPTS ${getAttr targetProperty (config.deployment)} 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
|
||||||
|
|
||||||
rollback=$((rollback + 1))
|
rollback=$((rollback + 1))
|
||||||
fi
|
fi
|
||||||
@ -32,33 +29,31 @@ let
|
|||||||
) (attrNames network)
|
) (attrNames network)
|
||||||
;
|
;
|
||||||
|
|
||||||
generateDistributionPhase = network: infrastructure: configs:
|
generateDistributionPhase = network: configs:
|
||||||
concatMapStrings (configurationName:
|
concatMapStrings (configurationName:
|
||||||
let
|
let
|
||||||
infrastructureElement = getAttr configurationName infrastructure;
|
|
||||||
config = getAttr configurationName configs;
|
config = getAttr configurationName configs;
|
||||||
in
|
in
|
||||||
''
|
''
|
||||||
echo "=== copy system closure to ${getAttr targetProperty infrastructureElement} ==="
|
echo "=== copy system closure to ${getAttr targetProperty (config.deployment)} ==="
|
||||||
nix-copy-closure --to ${getAttr targetProperty infrastructureElement} ${config.system.build.toplevel}
|
nix-copy-closure --to ${getAttr targetProperty (config.deployment)} ${config.system.build.toplevel}
|
||||||
''
|
''
|
||||||
) (attrNames network)
|
) (attrNames network)
|
||||||
;
|
;
|
||||||
|
|
||||||
generateActivationPhase = network: infrastructure: configs:
|
generateActivationPhase = network: configs:
|
||||||
concatMapStrings (configurationName:
|
concatMapStrings (configurationName:
|
||||||
let
|
let
|
||||||
infrastructureElement = getAttr configurationName infrastructure;
|
|
||||||
config = getAttr configurationName configs;
|
config = getAttr configurationName configs;
|
||||||
in
|
in
|
||||||
''
|
''
|
||||||
echo "=== activating system configuration on ${getAttr targetProperty infrastructureElement} ==="
|
echo "=== activating system configuration on ${getAttr targetProperty (config.deployment)} ==="
|
||||||
ssh $NIX_SSHOPTS ${getAttr targetProperty infrastructureElement} 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 --set ${config.system.build.toplevel} ||
|
||||||
(ssh $NIX_SSHOPTS ${getAttr targetProperty infrastructureElement} nix-env -p /nix/var/nix/profiles/system --rollback; rollbackSucceeded)
|
(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 (config.deployment)} /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 (config.deployment)} 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
|
||||||
rollbackSucceeded
|
rollbackSucceeded
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -67,22 +62,21 @@ let
|
|||||||
) (attrNames network)
|
) (attrNames network)
|
||||||
;
|
;
|
||||||
|
|
||||||
evaluateMachines = network: infrastructure:
|
evaluateMachines = network:
|
||||||
listToAttrs (map (configurationName:
|
listToAttrs (map (configurationName:
|
||||||
let
|
let
|
||||||
configuration = getAttr configurationName network;
|
configuration = getAttr configurationName network;
|
||||||
system = (getAttr configurationName infrastructure).system;
|
|
||||||
in
|
in
|
||||||
{ name = configurationName;
|
{ name = configurationName;
|
||||||
value = (import "${nixos}/lib/eval-config.nix" {
|
value = (import "${nixos}/lib/eval-config.nix" {
|
||||||
inherit nixpkgs system;
|
inherit nixpkgs;
|
||||||
modules = [ configuration ];
|
modules = [ configuration ];
|
||||||
extraArgs = evaluateMachines network infrastructure;
|
extraArgs = evaluateMachines network;
|
||||||
}).config; }
|
}).config; }
|
||||||
) (attrNames (network)))
|
) (attrNames (network)))
|
||||||
;
|
;
|
||||||
|
|
||||||
configs = evaluateMachines network infrastructure;
|
configs = evaluateMachines network;
|
||||||
in
|
in
|
||||||
pkgs.stdenv.mkDerivation {
|
pkgs.stdenv.mkDerivation {
|
||||||
name = "deploy-script";
|
name = "deploy-script";
|
||||||
@ -100,18 +94,18 @@ pkgs.stdenv.mkDerivation {
|
|||||||
rollbackSucceeded()
|
rollbackSucceeded()
|
||||||
{
|
{
|
||||||
rollback=0
|
rollback=0
|
||||||
${generateRollbackSucceededPhase network infrastructure configs}
|
${generateRollbackSucceededPhase network configs}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Distribution phase
|
# Distribution phase
|
||||||
|
|
||||||
${generateDistributionPhase network infrastructure configs}
|
${generateDistributionPhase network configs}
|
||||||
|
|
||||||
# Activation phase
|
# Activation phase
|
||||||
|
|
||||||
succeeded=0
|
succeeded=0
|
||||||
|
|
||||||
${generateActivationPhase network infrastructure configs}
|
${generateActivationPhase network configs}
|
||||||
EOF
|
EOF
|
||||||
chmod +x $out/bin/deploy-systems
|
chmod +x $out/bin/deploy-systems
|
||||||
'';
|
'';
|
||||||
|
@ -4,18 +4,17 @@
|
|||||||
|
|
||||||
showUsage()
|
showUsage()
|
||||||
{
|
{
|
||||||
echo "Usage: $0 -n network_expr -i infrastructure_expr"
|
echo "Usage: $0 network_expr"
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo
|
echo
|
||||||
echo "-n,--network Network Nix expression which captures properties of machines in the network"
|
echo "--show-trace Shows an output trace"
|
||||||
echo "-i,--infrastructure Infrastructure Nix expression which captures properties of machines in the network"
|
echo "--no-out-link Do not create a 'result' symlink"
|
||||||
echo "--show-trace Shows an output trace"
|
echo "-h,--help Shows the usage of this command"
|
||||||
echo "-h,--help Shows the usage of this command"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Parse valid argument options
|
# 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 ]
|
if [ $? != 0 ]
|
||||||
then
|
then
|
||||||
@ -30,15 +29,12 @@ eval set -- "$PARAMS"
|
|||||||
while [ "$1" != "--" ]
|
while [ "$1" != "--" ]
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-n|--network)
|
|
||||||
networkExpr=`readlink -f $2`
|
|
||||||
;;
|
|
||||||
-i|--infrastructure)
|
|
||||||
infrastructureExpr=`readlink -f $2`
|
|
||||||
;;
|
|
||||||
--show-trace)
|
--show-trace)
|
||||||
showTraceArg="--show-trace"
|
showTraceArg="--show-trace"
|
||||||
;;
|
;;
|
||||||
|
--no-out-link)
|
||||||
|
noOutLinkArg="--no-out-link"
|
||||||
|
;;
|
||||||
-h|--help)
|
-h|--help)
|
||||||
showUsage
|
showUsage
|
||||||
exit 0
|
exit 0
|
||||||
@ -48,27 +44,24 @@ do
|
|||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
|
shift
|
||||||
|
|
||||||
# Validate the given options
|
# 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" ]
|
if [ -z "$NIXOS" ]
|
||||||
then
|
then
|
||||||
NIXOS=/etc/nixos/nixos
|
NIXOS=/etc/nixos/nixos
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$@" = "" ]
|
||||||
|
then
|
||||||
|
echo "ERROR: A network Nix expression must be specified!" >&2
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
networkExpr=$(readlink -f $@)
|
||||||
|
fi
|
||||||
|
|
||||||
# Deploy the network
|
# Deploy the network
|
||||||
|
|
||||||
nix-build $NIXOS/modules/installer/tools/nixos-deploy-network/deploy.nix --argstr networkExpr $networkExpr --argstr infrastructureExpr $infrastructureExpr $showTraceArg
|
vms=`nix-build $NIXOS/modules/installer/tools/nixos-deploy-network/deploy.nix --argstr networkExpr $networkExpr $showTraceArg $noOutLinkArg`
|
||||||
./result/bin/deploy-systems
|
$vms/bin/deploy-systems
|
||||||
rm -f result
|
|
||||||
|
Loading…
Reference in New Issue
Block a user