Define the script within nix, not bash.
This commit is contained in:
parent
6766412769
commit
d9e1a0153f
1 changed files with 20 additions and 17 deletions
33
flake.nix
33
flake.nix
|
@ -17,26 +17,29 @@
|
||||||
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: final.writeScript "deploy-${machine}.sh" ''
|
mkDeployScript = machine: let
|
||||||
|
inherit (builtins) abort;
|
||||||
|
|
||||||
|
n = flake.nixosConfigurations.${machine}._module.args.nixinate;
|
||||||
|
user = n.sshUser;
|
||||||
|
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'";
|
||||||
|
script = ''
|
||||||
set -e
|
set -e
|
||||||
SSH_USER=${flake.nixosConfigurations.${machine}._module.args.nixinate.sshUser}
|
|
||||||
SSH_HOST=${flake.nixosConfigurations.${machine}._module.args.nixinate.host}
|
|
||||||
BUILD_ON=${flake.nixosConfigurations.${machine}._module.args.nixinate.buildOn}
|
|
||||||
echo "🚀 Deploying nixosConfigurations.${machine} from ${flake}"
|
echo "🚀 Deploying nixosConfigurations.${machine} from ${flake}"
|
||||||
echo "👤 SSH User: $SSH_USER"
|
echo "👤 SSH User: ${user}"
|
||||||
echo "🌐 SSH Host: $SSH_HOST"
|
echo "🌐 SSH Host: ${host}"
|
||||||
if [ $BUILD_ON = "remote" ]; then
|
'' + (if remote then ''
|
||||||
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}/* $SSH_USER@$SSH_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 $SSH_USER@$SSH_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}' )
|
||||||
elif [ $BUILD_ON = "local" ]; then
|
'' 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 $SSH_USER@$SSH_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 )
|
||||||
else
|
'');
|
||||||
echo "_module.args.nixinate.buildOn is not set to a valid value of 'local' or 'remote'"
|
in final.writeScript "deploy-${machine}.sh" script;
|
||||||
fi
|
|
||||||
'';
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
nixinate =
|
nixinate =
|
||||||
|
|
Loading…
Add table
Reference in a new issue