add remote build to update script
This commit is contained in:
parent
ab4d9e6f81
commit
f1e58a9285
1 changed files with 16 additions and 11 deletions
|
@ -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() {
|
||||||
|
@ -21,11 +22,13 @@ function usage() {
|
||||||
echo ""
|
echo ""
|
||||||
echo "Advanced usage: nixos-upgrade-script.sh [-o|--operation operation] [-f|--flake path-to-flake] [extra nixos-rebuild parameters]"
|
echo "Advanced usage: nixos-upgrade-script.sh [-o|--operation operation] [-f|--flake path-to-flake] [extra nixos-rebuild parameters]"
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo " -h, --help Show this help screen."
|
echo " -h, --help Show this help screen."
|
||||||
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 " -u, --user Which user account to run git commands under."
|
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 ""
|
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
|
/run/wrappers/bin/sudo -u $user nix flake update --commit-lock-file && /run/wrappers/bin/sudo -u $user git push
|
||||||
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
|
|
||||||
|
|
||||||
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"
|
||||||
|
|
Loading…
Add table
Reference in a new issue