Rework script to support local building
This commit is contained in:
parent
cb711717de
commit
49e70e393a
|
@ -3,16 +3,45 @@
|
|||
|
||||
# shellcheck shell=bash
|
||||
|
||||
set -e
|
||||
set -eou pipefail
|
||||
|
||||
TARGET=$1
|
||||
if [ -z "$TARGET" ]; then
|
||||
echo "Usage: $0 <host.hq.c3d2.de>"
|
||||
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"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [[ $# == 0 ]]; then
|
||||
show_help
|
||||
fi
|
||||
HOSTNAME=$(echo "$TARGET" | cut -d . -f 1)
|
||||
|
||||
rsync -az "$(dirname "$0")" root@"$TARGET":nix-config
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "${1:-}" in
|
||||
"" | "-h" | "--help")
|
||||
show_help
|
||||
;;
|
||||
"--build-local")
|
||||
build_local=true
|
||||
;;
|
||||
*)
|
||||
target=$1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
echo "$HOSTNAME> nixos-rebuild switch"
|
||||
exec ssh root@"$TARGET" "nixos-rebuild --flake ./nix-config#$HOSTNAME switch"
|
||||
if [[ -v build_local ]]; then
|
||||
nix --experimental-features 'nix-command flakes' -Lv build ".#nixosConfigurations.$target.config.system.build.toplevel"
|
||||
store_path=$(readlink -f result)
|
||||
nix-copy-closure --to root@"$target" -v "$store_path"
|
||||
ssh root@"$target" "$store_path/bin/switch-to-configuration" switch
|
||||
else
|
||||
hostname=$(echo "$target" | cut -d . -f 1)
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue