2021-09-06 20:49:45 +02:00
|
|
|
#! /usr/bin/env nix-shell
|
2021-09-07 21:42:53 +02:00
|
|
|
#! nix-shell -i bash -p rsync
|
2021-09-06 20:49:45 +02:00
|
|
|
|
|
|
|
# shellcheck shell=bash
|
2021-03-28 21:11:13 +02:00
|
|
|
|
2021-09-07 22:03:47 +02:00
|
|
|
set -eou pipefail
|
2021-03-28 21:11:13 +02:00
|
|
|
|
2021-09-07 22:03:47 +02:00
|
|
|
function show_help() {
|
|
|
|
echo "Usage:"
|
|
|
|
echo "$0 [--build-local] <host.hq.c3d2.de>"
|
|
|
|
echo "--help Show this help."
|
|
|
|
echo "--build-local Build config locally and copy it to the target system via nix-copy-closure"
|
2021-08-21 01:12:56 +02:00
|
|
|
exit 1
|
2021-09-07 22:03:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if [[ $# == 0 ]]; then
|
|
|
|
show_help
|
2021-03-28 21:11:13 +02:00
|
|
|
fi
|
|
|
|
|
2021-09-07 22:03:47 +02:00
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
case "${1:-}" in
|
|
|
|
"" | "-h" | "--help")
|
|
|
|
show_help
|
|
|
|
;;
|
|
|
|
"--build-local")
|
|
|
|
build_local=true
|
|
|
|
;;
|
|
|
|
*)
|
2021-10-02 20:28:46 +02:00
|
|
|
# strip hostname and user
|
|
|
|
host=$1
|
|
|
|
target=${1//.hq.c3d2.de/}
|
|
|
|
target=${target//.c3d2.de/}
|
2021-09-07 22:03:47 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ -v build_local ]]; then
|
|
|
|
nix --experimental-features 'nix-command flakes' -Lv build ".#nixosConfigurations.$target.config.system.build.toplevel"
|
|
|
|
store_path=$(readlink -f result)
|
2021-10-02 20:28:46 +02:00
|
|
|
nix-copy-closure --to root@"$host" -v "$store_path"
|
|
|
|
ssh root@"$host" "$store_path/bin/switch-to-configuration" switch
|
2021-09-07 22:03:47 +02:00
|
|
|
else
|
|
|
|
hostname=$(echo "$target" | cut -d . -f 1)
|
2021-03-28 21:11:13 +02:00
|
|
|
|
2021-09-07 22:03:47 +02:00
|
|
|
rsync -az "$(dirname "$0")" root@"$target":nix-config
|
|
|
|
|
|
|
|
echo "$hostname> nixos-rebuild switch"
|
|
|
|
exec ssh root@"$target" "nixos-rebuild --flake ./nix-config#$hostname switch"
|
|
|
|
fi
|