deploy-flake: always use target hostname for safety

This commit is contained in:
Astro 2022-01-07 00:15:43 +01:00
parent 4337e4a77e
commit 365757073a
1 changed files with 9 additions and 9 deletions

View File

@ -26,25 +26,25 @@ while [[ $# -gt 0 ]]; do
build_local=true build_local=true
;; ;;
*) *)
# strip hostname and user
host=$1 host=$1
target=${1//.hq.c3d2.de/}
target=${target//.c3d2.de/}
;; ;;
esac esac
shift shift
done done
if [[ -v build_local ]]; then if [[ -v build_local ]]; then
nix --experimental-features 'nix-command flakes' -Lv build ".#nixosConfigurations.$target.config.system.build.toplevel" hostname=$(ssh root@"$host" hostname)
echo "$hostname> nix build"
nix --experimental-features 'nix-command flakes' -Lv build ".#nixosConfigurations.$hostname.config.system.build.toplevel"
store_path=$(readlink -f result) store_path=$(readlink -f result)
echo "$hostname> nix copy"
nix --experimental-features 'nix-command flakes' copy --to ssh://root@"$host" -v "$store_path" nix --experimental-features 'nix-command flakes' copy --to ssh://root@"$host" -v "$store_path"
echo "$hostname> switch-to-configuration switch"
ssh root@"$host" "$store_path/bin/switch-to-configuration" switch ssh root@"$host" "$store_path/bin/switch-to-configuration" switch
else else
hostname=$(echo "$target" | cut -d . -f 1) rsync -az "$(dirname "$0")" root@"$host":nix-config
rsync -az "$(dirname "$0")" root@"$target":nix-config echo "> nixos-rebuild switch"
exec ssh root@"$host" 'nixos-rebuild --flake git+file://`pwd`/nix-config#`hostname` --override-input secrets git+file://`pwd`/nix-config/secrets switch'
echo "$hostname> nixos-rebuild switch"
exec ssh root@"$target" "nixos-rebuild --flake ./nix-config#`hostname` switch"
fi fi