Add dry runs. #7
1 changed files with 19 additions and 4 deletions
23
flake.nix
23
flake.nix
|
@ -17,7 +17,7 @@
|
||||||
let
|
let
|
||||||
machines = builtins.attrNames flake.nixosConfigurations;
|
machines = builtins.attrNames flake.nixosConfigurations;
|
||||||
validMachines = final.lib.remove "" (final.lib.forEach machines (x: final.lib.optionalString (flake.nixosConfigurations."${x}"._module.args ? nixinate) "${x}" ));
|
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;
|
inherit (builtins) abort;
|
||||||
|
|
||||||
n = flake.nixosConfigurations.${machine}._module.args.nixinate;
|
n = flake.nixosConfigurations.${machine}._module.args.nixinate;
|
||||||
|
@ -25,6 +25,7 @@
|
||||||
host = n.host;
|
host = n.host;
|
||||||
where = n.buildOn or "remote";
|
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'";
|
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 = ''
|
script = ''
|
||||||
set -e
|
set -e
|
||||||
echo "🚀 Deploying nixosConfigurations.${machine} from ${flake}"
|
echo "🚀 Deploying nixosConfigurations.${machine} from ${flake}"
|
||||||
|
@ -34,10 +35,10 @@
|
||||||
echo "🚀 Sending flake to ${machine} via rsync:"
|
echo "🚀 Sending flake to ${machine} via rsync:"
|
||||||
( set -x; ${final.rsync}/bin/rsync -q -vz --recursive --zc=zstd ${flake}/* ${user}@${host}:/tmp/nixcfg/ )
|
( set -x; ${final.rsync}/bin/rsync -q -vz --recursive --zc=zstd ${flake}/* ${user}@${host}:/tmp/nixcfg/ )
|
||||||
echo "🤞 Activating configuration on ${machine} via ssh:"
|
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 ''
|
'' else ''
|
||||||
echo "🔨 Building system closure locally, copying it to remote store and activating it:"
|
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 final.writeScript "deploy-${machine}.sh" script;
|
||||||
in
|
in
|
||||||
|
@ -49,7 +50,21 @@
|
||||||
(x:
|
(x:
|
||||||
{
|
{
|
||||||
type = "app";
|
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