From 1c355a30f5af4ee742ca06a5901070937db1479b Mon Sep 17 00:00:00 2001 From: Mohammad Rafiq Date: Sun, 1 Jun 2025 20:01:14 +0800 Subject: [PATCH] feat(packages/rebuild): make test shell not open by default= --- packages/rebuild/default.nix | 38 ++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/packages/rebuild/default.nix b/packages/rebuild/default.nix index b7482dc..7c22a41 100644 --- a/packages/rebuild/default.nix +++ b/packages/rebuild/default.nix @@ -1,6 +1,22 @@ { pkgs, ... }: pkgs.writeShellScriptBin "rebuild" # sh '' + TEST_SHELL=false + REMOTE_HOSTS=() + + while [[ $# -gt 0 ]]; do + case "$1" in + --test-shell | -t) + TEST_SHELL=true + shift + ;; + *) + REMOTE_HOSTS+="$1" + shift + ;; + esac + done + if [ ! -f "flake.nix" ]; then echo "Error: flake.nix not found in the current directory. Exiting." exit 1 # Indicate an error @@ -8,9 +24,13 @@ pkgs.writeShellScriptBin "rebuild" # sh git add . - if [ $# -gt 0 ]; then - for arg in "$@"; do - nixos-rebuild switch --flake .#"$arg" --target-host "$arg" --use-remote-sudo + if [ ''${#REMOTE_HOSTS[@]} -gt 0 ]; then + for host in "$REMOTE_HOSTS[@]"; do + echo "Rebuilding $host..." + nixos-rebuild switch --flake .#"$host" --target-host "$host" --use-remote-sudo || { + echo "Error: nixos-rebuild switch failed for $host. Check the output." + exit 1 + } done exit 0 fi @@ -24,11 +44,13 @@ pkgs.writeShellScriptBin "rebuild" # sh git diff HEAD --color=always --stat --patch - (export PS1="Test shell> " - exec ${pkgs.bash}/bin/bash) || { - ${pkgs.cowsay}/bin/cowsay "You aborted." - exit 1 - } + if "$TEST_SHELL"; then + (export PS1="Test shell> " + exec ${pkgs.bash}/bin/bash) || { + ${pkgs.cowsay}/bin/cowsay "You aborted." + exit 1 + } + fi export NIXOS_LABEL="$(date +%d%m%y\ %H:%M:%S)" nh os boot . || {