deploy-local: Use custom implementation

Using nixos-rebuild for this, while being easy, often was difficult.
Simon Bruder 2023-05-31 17:50:51 +02:00
parent da3becd704
commit 88f97c27de
Signed by: simon
GPG Key ID: 8D3C82F9F309F8EC
1 changed files with 15 additions and 6 deletions

View File

@ -108,12 +108,21 @@
deploy-local = lib.recurseIntoAttrs (lib.mapAttrs
(hostname: machine: pkgs.writeShellScript "deploy-local-${hostname}" ''
${pkgs.nixos-rebuild}/bin/nixos-rebuild \
switch \
--flake .#${hostname} \
--build-host localhost \
--target-host root@${machine.config.deployment.targetHost} \
--use-substitutes
set -euo pipefail
closure="$(nix build -L --print-out-paths .#nixosConfigurations.${hostname}.config.system.build.toplevel)"
nix copy \
-s \
-L \
--to ssh://root@${machine.config.deployment.targetHost} \
"$closure"
ssh root@${machine.config.deployment.targetHost} nix-env -p /nix/var/nix/profiles/system --set ''${closure}
ssh root@${machine.config.deployment.targetHost} ''${closure}/bin/switch-to-configuration switch
return="$?"
if [ "$return" != 0 ]; then
echo "Error(s) occurred while Switching configuration"
exit "$retuen"
fi
'')
self.nixosConfigurations);