updated rebuild script to auto delete result

This commit is contained in:
Leyla Becker 2024-09-22 13:30:23 -05:00
parent 8f36a609db
commit 1e0218d928

View file

@ -1,5 +1,12 @@
#!/usr/bin/env bash #!/usr/bin/env bash
if [ -d "result" ];
then
preserve_result=true
else
preserve_result=false
fi
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
--target*|-t*) --target*|-t*)
@ -18,12 +25,20 @@ while [ $# -gt 0 ]; do
if [[ "$1" != *=* ]]; then shift; fi if [[ "$1" != *=* ]]; then shift; fi
user="${1#*=}" user="${1#*=}"
;; ;;
--preserve-result)
preserve_result=true
;;
--no-preserve-result)
preserve_result=false
;;
--help|-h) --help|-h)
echo "--help -h: print this message" echo "--help -h: print this message"
echo "--target -t: set the target system to rebuild on" echo "--target -t: set the target system to rebuild on"
echo "--flake -f: set the flake to rebuild on the target system" echo "--flake -f: set the flake to rebuild on the target system"
echo "--mode -m: set the mode to rebuild flake as on the target system" echo "--mode -m: set the mode to rebuild flake as on the target system"
echo "--user -u: set the user to rebuild flake as on the target system" echo "--user -u: set the user to rebuild flake as on the target system"
echo "--preserve-result: do not remove the generated result folder after building"
echo "--no-preserve-result: remove any result folder after building"
exit 0 exit 0
;; ;;
*) *)
@ -39,9 +54,17 @@ flake=${flake:-$target}
mode=${mode:-switch} mode=${mode:-switch}
user=${user:-$USER} user=${user:-$USER}
if [[ "$target" == "$(hostname)" ]] if [[ "$target" == "$(hostname)" ]];
then then
nixos-rebuild $mode --use-remote-sudo --flake .#$flake nixos-rebuild $mode --use-remote-sudo --flake .#$flake
else else
nixos-rebuild $mode --use-remote-sudo --target-host $user@$target --flake .#$flake nixos-rebuild $mode --use-remote-sudo --target-host $user@$target --flake .#$flake
fi fi
if [ -d "result" ];
then
if [[ "$preserve_result" == "false" ]];
then
rm -r result
fi
fi