New option --and-reboot to immediately reboot host after applying config

This commit is contained in:
2025-06-01 22:09:53 +02:00
parent 202f4a1a57
commit 5f3748df43
2 changed files with 28 additions and 0 deletions

16
bij.sh
View File

@@ -7,6 +7,7 @@ TARGET=
ON_NEXT_BOOT=
USE_SUBSTITUTES="1"
USE_REMOTE_SUDO="1"
AND_REBOOT=
ARGS=()
OPTS=()
@@ -43,6 +44,10 @@ while [[ $# -gt 0 ]]; do
USE_REMOTE_SUDO=""
shift
;;
--and-reboot)
AND_REBOOT="1"
shift
;;
--)
shift
OPTS=( "$@" )
@@ -106,9 +111,20 @@ if [[ -n "${ON_NEXT_BOOT}" ]]; then
APPLY_OPERATION="boot"
fi
REBOOT_OPTS=()
if [[ -n "${USE_REMOTE_SUDO}" ]]; then
REBOOT_OPTS+=("sudo")
fi
REBOOT_OPTS+=("reboot")
case "${COMMAND}" in
apply)
nixos-rebuild "${APPLY_OPERATION}" --flake "${FLAKE_STORE_PATH}#${HOST}" --target-host "${TARGET}" "${APPLY_OPTS[@]}"
if [[ -n "${AND_REBOOT}" ]]; then
ssh -t "${TARGET}" "${REBOOT_OPTS[@]}"
fi
;;
build)
nixos-rebuild build --flake "${FLAKE_STORE_PATH}#${HOST}"