Add dry runs. #7
1 changed files with 19 additions and 4 deletions
23
flake.nix
23
flake.nix
|
@ -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;
|
||||
});
|
||||
}
|
||||
)
|
||||
);
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue