1
0
Fork 0

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
;;
*)
# strip hostname and user
host=$1
target=${1//.hq.c3d2.de/}
target=${target//.c3d2.de/}
;;
esac
shift
done
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)
echo "$hostname> nix copy"
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
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 "$hostname> nixos-rebuild switch"
exec ssh root@"$target" "nixos-rebuild --flake ./nix-config#`hostname` switch"
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'
fi