Add dry runs.

Co-authored-by: Mason Mackaman <masondeanm@aol.com>
This commit is contained in:
Chloe Kever 2022-02-15 18:42:53 -08:00
parent 48f1c6d1df
commit 2a107a1b7b

View file

@ -17,7 +17,7 @@
let
machines = builtins.attrNames flake.nixosConfigurations;
validMachines = final.lib.remove "" (final.lib.forEach machines (x: final.lib.optionalString (flake.nixosConfigurations."${x}"._module.args ? nixinate) "${x}" ));
mkDeployScript = machine: let
mkDeployScript = { machine, dryRun }: let
inherit (builtins) abort;
n = flake.nixosConfigurations.${machine}._module.args.nixinate;
@ -25,6 +25,7 @@
host = n.host;
where = n.buildOn or "remote";
remote = if where == "remote" then true else if where == "local" then false else abort "_module.args.nixinate.buildOn is not set to a valid value of 'local' or 'remote'";
switch = if dryRun then "dry-activate" else "switch";
script = ''
set -e
echo "🚀 Deploying nixosConfigurations.${machine} from ${flake}"
@ -34,10 +35,10 @@
echo "🚀 Sending flake to ${machine} via rsync:"
( set -x; ${final.rsync}/bin/rsync -q -vz --recursive --zc=zstd ${flake}/* ${user}@${host}:/tmp/nixcfg/ )
echo "🤞 Activating configuration on ${machine} via ssh:"
( set -x; ${final.openssh}/bin/ssh -t ${user}@${host} 'sudo nixos-rebuild switch --flake /tmp/nixcfg#${machine}' )
( set -x; ${final.openssh}/bin/ssh -t ${user}@${host} 'sudo nixos-rebuild ${switch} --flake /tmp/nixcfg#${machine}' )
'' else ''
echo "🔨 Building system closure locally, copying it to remote store and activating it:"
( set -x; NIX_SSHOPTS="-t" ${final.nixos-rebuild}/bin/nixos-rebuild switch --flake ${flake}#${machine} --target-host ${user}@${host} --use-remote-sudo )
( set -x; NIX_SSHOPTS="-t" ${final.nixos-rebuild}/bin/nixos-rebuild ${switch} --flake ${flake}#${machine} --target-host ${user}@${host} --use-remote-sudo )
'');
in final.writeScript "deploy-${machine}.sh" script;
in
@ -49,9 +50,23 @@
(x:
{
type = "app";
program = toString (mkDeployScript x);
program = toString (mkDeployScript {
machine = x;
dryRun = false;
});
}
)
// nixpkgs.lib.genAttrs
(map (a: a + "-dry-run") validMachines)
(x:
{
type = "app";
program = toString (mkDeployScript {
machine = x;
dryRun = true;
});
}
)
);
};
};