From 88f97c27def7e7e4f11ce5b800dccb9e7f13294f Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Wed, 31 May 2023 17:50:51 +0200 Subject: [PATCH] deploy-local: Use custom implementation Using nixos-rebuild for this, while being easy, often was difficult. --- flake.nix | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index 82a92bc..55bcf8c 100644 --- a/flake.nix +++ b/flake.nix @@ -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);