diff --git a/bin/auto-update-nixos b/bin/auto-update-nixos index 7d36b4a..3d220e8 100755 --- a/bin/auto-update-nixos +++ b/bin/auto-update-nixos @@ -8,6 +8,7 @@ flakeDir="${FLAKE_DIR}" # Path to the flake file (and op 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) reboot=false +remote=false remainingArgs="" # All remaining arguments that haven't yet been processed (will be passed to nixos-rebuild) function usage() { @@ -21,11 +22,13 @@ function usage() { echo "" echo "Advanced usage: nixos-upgrade-script.sh [-o|--operation operation] [-f|--flake path-to-flake] [extra nixos-rebuild parameters]" echo "Options:" - echo " -h, --help Show this help screen." - echo " -o, --operation The nixos-rebuild operation to perform." - echo " -f, --flake The path to your flake.nix file (and optionally, the hostname to build)." - echo " -U, --update Update and commit flake.lock." - echo " -u, --user Which user account to run git commands under." + echo " -h, --help Show this help screen." + echo " -o, --operation The nixos-rebuild operation to perform." + echo " -f, --flake The path to your flake.nix file (and optionally, the hostname to build)." + echo " -U, --update Update and commit flake.lock." + echo " -R, --build-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 "" exit 2 } @@ -47,6 +50,12 @@ while [[ $# -gt 0 ]]; do reboot=true shift ;; + --build-host|-R) + remote=true + host="$2" + shift + shift + ;; --operation|-o) operation="$2" 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 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 -else - echo "Skipping 'nix flake update'..." -fi +/run/wrappers/bin/sudo -u $user nix flake update --commit-lock-file && /run/wrappers/bin/sudo -u $user git push options="--flake $flakeDir $remainingArgs --use-remote-sudo" echo "Running this operation: 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"