add remote build to update script

This commit is contained in:
Sam 2025-01-23 23:40:11 +00:00
parent ab4d9e6f81
commit f1e58a9285

View file

@ -8,6 +8,7 @@ flakeDir="${FLAKE_DIR}" # Path to the flake file (and op
update=false # Whether to update flake.lock (false by default) update=false # Whether to update flake.lock (false by default)
user=$(/run/current-system/sw/bin/whoami) # Which user account to use for git commands (defaults to whoever called the script) user=$(/run/current-system/sw/bin/whoami) # Which user account to use for git commands (defaults to whoever called the script)
reboot=false reboot=false
remote=false
remainingArgs="" # All remaining arguments that haven't yet been processed (will be passed to nixos-rebuild) remainingArgs="" # All remaining arguments that haven't yet been processed (will be passed to nixos-rebuild)
function usage() { function usage() {
@ -25,6 +26,8 @@ function usage() {
echo " -o, --operation The nixos-rebuild operation to perform." echo " -o, --operation The nixos-rebuild operation to perform."
echo " -f, --flake <path> The path to your flake.nix file (and optionally, the hostname to build)." echo " -f, --flake <path> The path to your flake.nix file (and optionally, the hostname to build)."
echo " -U, --update Update and commit flake.lock." echo " -U, --update Update and commit flake.lock."
echo " -R, --build-host <user@host> Build on remote host."
echo " -r, --reboot Reboots system is there is a kernel or init update"
echo " -u, --user Which user account to run git commands under." echo " -u, --user Which user account to run git commands under."
echo "" echo ""
exit 2 exit 2
@ -47,6 +50,12 @@ while [[ $# -gt 0 ]]; do
reboot=true reboot=true
shift shift
;; ;;
--build-host|-R)
remote=true
host="$2"
shift
shift
;;
--operation|-o) --operation|-o)
operation="$2" operation="$2"
shift shift
@ -84,16 +93,12 @@ echo "Pulling the latest version of the repository..."
/run/wrappers/bin/sudo -u $user git stash /run/wrappers/bin/sudo -u $user git stash
/run/wrappers/bin/sudo -u $user git pull /run/wrappers/bin/sudo -u $user git pull
if [ $update = true ]; then
echo "Updating flake.lock..."
/run/wrappers/bin/sudo -u $user nix flake update --commit-lock-file && /run/wrappers/bin/sudo -u $user git push /run/wrappers/bin/sudo -u $user nix flake update --commit-lock-file && /run/wrappers/bin/sudo -u $user git push
else
echo "Skipping 'nix flake update'..."
fi
options="--flake $flakeDir $remainingArgs --use-remote-sudo" options="--flake $flakeDir $remainingArgs --use-remote-sudo"
echo "Running this operation: nixos-rebuild $operation $options" echo "Running this operation: nixos-rebuild $operation $options"
/run/wrappers/bin/sudo -u root /run/current-system/sw/bin/nixos-rebuild $operation $options /run/wrappers/bin/sudo -u root /run/current-system/sw/bin/nixos-rebuild $operation $options
echo "Checking if reboot is necessary" echo "Checking if reboot is necessary"