Modified the nixos-deploy-network script to use a 2PC-like approach illustrated in the Disnix HotSWUp paper for system configurations
svn path=/nixos/trunk/; revision=24352
This commit is contained in:
parent
341698c367
commit
936e4e73d7
|
@ -2,33 +2,71 @@
|
||||||
, nixpkgs ? /etc/nixos/nixpkgs
|
, nixpkgs ? /etc/nixos/nixpkgs
|
||||||
, networkExpr
|
, networkExpr
|
||||||
, infrastructureExpr
|
, infrastructureExpr
|
||||||
|
, targetProperty ? "hostname"
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
pkgs = import nixpkgs {};
|
pkgs = import nixpkgs {};
|
||||||
|
|
||||||
inherit (builtins) attrNames getAttr listToAttrs concatMapStrings;
|
inherit (builtins) attrNames getAttr listToAttrs;
|
||||||
|
inherit (pkgs.lib) concatMapStrings;
|
||||||
|
|
||||||
network = import networkExpr;
|
network = import networkExpr;
|
||||||
infrastructure = import infrastructureExpr;
|
infrastructure = import infrastructureExpr;
|
||||||
|
|
||||||
generateScript = network: infrastructure: configs:
|
generateRollbackSucceededPhase = network: infrastructure: configs:
|
||||||
concatMapStrings (configurationName:
|
concatMapStrings (configurationName:
|
||||||
let
|
let
|
||||||
infrastructureElement = getAttr configurationName infrastructure;
|
infrastructureElement = getAttr configurationName infrastructure;
|
||||||
config = getAttr configurationName configs;
|
config = getAttr configurationName configs;
|
||||||
in
|
in
|
||||||
''
|
''
|
||||||
echo "=== upgrading ${infrastructureElement.hostName} ==="
|
if [ "$rollback" != "$succeeded" ]
|
||||||
nix-copy-closure --to ${infrastructureElement.hostName} ${config.system.build.toplevel} \
|
then
|
||||||
&& ssh $NIX_SSHOPTS ${infrastructureElement.hostName} 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
|
||||||
&& ssh $NIX_SSHOPTS ${infrastructureElement.hostName} ${config.system.build.toplevel}/bin/switch-to-configuration switch \
|
ssh $NIX_SSHOPTS ${getAttr targetProperty infrastructureElement} /nix/var/nix/profiles/bin/switch-to-configuration switch
|
||||||
&& { succeeded=$((succeeded + 1)); } \
|
|
||||||
|| { failed=$((failed + 1)); echo 'WARNING: upgrade of ${infrastructureElement.hostName} failed!'; }
|
rollback=$((rollback + 1))
|
||||||
|
fi
|
||||||
|
''
|
||||||
|
) (attrNames network)
|
||||||
|
;
|
||||||
|
|
||||||
|
generateDistributionPhase = network: infrastructure: 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}
|
||||||
''
|
''
|
||||||
) (attrNames network)
|
) (attrNames network)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
generateActivationPhase = network: infrastructure: 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)
|
||||||
|
|
||||||
|
ssh $NIX_SSHOPTS ${getAttr targetProperty infrastructureElement} /nix/var/nix/profiles/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/bin/switch-to-configuration switch
|
||||||
|
rollbackSucceeded
|
||||||
|
)
|
||||||
|
|
||||||
|
succeeded=$((succeeded + 1))
|
||||||
|
''
|
||||||
|
) (attrNames network)
|
||||||
|
;
|
||||||
|
|
||||||
evaluateMachines = network: infrastructure:
|
evaluateMachines = network: infrastructure:
|
||||||
listToAttrs (map (configurationName:
|
listToAttrs (map (configurationName:
|
||||||
let
|
let
|
||||||
|
@ -48,13 +86,27 @@ let
|
||||||
in
|
in
|
||||||
pkgs.stdenv.mkDerivation {
|
pkgs.stdenv.mkDerivation {
|
||||||
name = "deploy-script";
|
name = "deploy-script";
|
||||||
buildCommand = ''
|
buildCommand =
|
||||||
|
''
|
||||||
ensureDir $out/bin
|
ensureDir $out/bin
|
||||||
cat > $out/bin/deploy-systems << "EOF"
|
cat > $out/bin/deploy-systems << "EOF"
|
||||||
#! ${pkgs.stdenv.shell} -e
|
#! ${pkgs.stdenv.shell} -e
|
||||||
failed=0; succeeded=0
|
|
||||||
${generateScript network infrastructure configs}
|
rollbackSucceeded()
|
||||||
echo "Upgrade of $failed machines failed, $succeeded machines succeeded.";
|
{
|
||||||
|
rollback=0
|
||||||
|
${generateRollbackSucceededPhase network infrastructure configs}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Distribution phase
|
||||||
|
|
||||||
|
${generateDistributionPhase network infrastructure configs}
|
||||||
|
|
||||||
|
# Activation phase
|
||||||
|
|
||||||
|
succeeded=0
|
||||||
|
|
||||||
|
${generateActivationPhase network infrastructure configs}
|
||||||
EOF
|
EOF
|
||||||
chmod +x $out/bin/deploy-systems
|
chmod +x $out/bin/deploy-systems
|
||||||
'';
|
'';
|
||||||
|
|
|
@ -68,6 +68,6 @@ fi
|
||||||
|
|
||||||
# Deploy the network
|
# Deploy the network
|
||||||
|
|
||||||
nix-build $NIXOS/deploy.nix --argstr networkExpr $networkExpr --argstr infrastructureExpr $infrastructureExpr $showTraceArg
|
nix-build $NIXOS/modules/installer/tools/nixos-deploy-network/deploy.nix --argstr networkExpr $networkExpr --argstr infrastructureExpr $infrastructureExpr $showTraceArg
|
||||||
./result/bin/deploy-systems
|
./result/bin/deploy-systems
|
||||||
rm -f result
|
rm -f result
|
||||||
|
|
Loading…
Reference in a new issue