From 3a626b64290805d297dc0265b04f3b34287b20e9 Mon Sep 17 00:00:00 2001 From: Myned <dev@bjork.tech> Date: Sat, 29 Mar 2025 18:13:38 -0500 Subject: [PATCH] nixos.sh: add sending power action to target --- options/custom/scripts/default.nix | 1 + options/custom/scripts/nixos.sh | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/options/custom/scripts/default.nix b/options/custom/scripts/default.nix index c792ced..2fc0cb6 100644 --- a/options/custom/scripts/default.nix +++ b/options/custom/scripts/default.nix @@ -132,6 +132,7 @@ in { nix nixos-rebuild nvd + openssh systemd ]) (bash "power" [ diff --git a/options/custom/scripts/nixos.sh b/options/custom/scripts/nixos.sh index 5481238..ea9a19d 100644 --- a/options/custom/scripts/nixos.sh +++ b/options/custom/scripts/nixos.sh @@ -47,13 +47,22 @@ _build() { fi fi - # TODO: Send to remote target if specified - # Invoke systemd to shutdown system + # Use systemd to act on system # Assumes errexit shell option is set if [[ "${argc_poweroff:-}" ]]; then - sudo systemctl poweroff + action=(systemctl poweroff) elif [[ "${argc_reboot:-}" ]]; then - sudo systemctl reboot + action=(systemctl reboot) + fi + + # Invoke action on remote target if specified + if [[ -v action ]]; then + if [[ "${argc_target:-}" ]]; then + # shellcheck disable=SC2029 + ssh root@"${argc_target}" "${action[@]}" + else + sudo "${action[@]}" + fi fi }