From 3b7379a1c5c60cf114f7582b003a40c2fc0c95cd Mon Sep 17 00:00:00 2001 From: Andre Date: Tue, 2 Apr 2024 09:23:28 -0400 Subject: [PATCH] Tweak upgrade script --- flake.lock | 6 +++--- hosts/common/nixos-upgrade.sh | 31 ++++++++++++++++++------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/flake.lock b/flake.lock index d053705..c4187c4 100644 --- a/flake.lock +++ b/flake.lock @@ -117,11 +117,11 @@ ] }, "locked": { - "lastModified": 1711915616, - "narHash": "sha256-co6LoFA+j6BZEeJNSR8nZ4oOort5qYPskjrDHBaJgmo=", + "lastModified": 1712016346, + "narHash": "sha256-O2nO7pD+krq+4HgkLB4VThRtAucIPfXDs/jJqCGlK1w=", "owner": "nix-community", "repo": "home-manager", - "rev": "820be197ccf3adaad9a8856ef255c13b6cc561a6", + "rev": "4be0464472675212654dedf3e021bd5f1d58b92f", "type": "github" }, "original": { diff --git a/hosts/common/nixos-upgrade.sh b/hosts/common/nixos-upgrade.sh index b5c90ac..2eb1913 100755 --- a/hosts/common/nixos-upgrade.sh +++ b/hosts/common/nixos-upgrade.sh @@ -26,10 +26,11 @@ while [[ $# -gt 0 ]]; do ;; -h|--help) usage - shift + exit ;; *) - break + echo "Unknown argument $1" + exit 1 ;; esac done @@ -39,19 +40,23 @@ echo "Using installation mode: $OPERATION" cd ~/Development/nix-configuration nix flake update nixos-rebuild build --flake . -echo "Updates to apply:" -nix store diff-closures /run/current-system ./result | awk '/[0-9] →|→ [0-9]/ && !/nixos/' || echo +UPDATES=$(nix store diff-closures /run/current-system ./result | awk '/[0-9] →|→ [0-9]/ && !/nixos/' || echo) -if [ $AUTOACCEPT == false ]; then - read -p "Continue with upgrade (y/n) ? " choice - case "$choice" in - y|Y|yes ) echo "Running nixos-rebuild $OPERATION :";; - n|N|no ) echo "Upgrade cancelled." && exit;; - * ) echo "Invalid option. Upgrade cancelled." && exit;; - esac +if [ $UPDATES ]; then + echo "NixOS updates to apply: " + echo $UPDATES + if [ $AUTOACCEPT == false ]; then + read -p "Continue with upgrade (y/n) ? " choice + case "$choice" in + y|Y|yes ) echo "Running nixos-rebuild $OPERATION :";; + n|N|no ) echo "Upgrade cancelled." && exit;; + * ) echo "Invalid option. Upgrade cancelled." && exit;; + esac + fi + sudo nixos-rebuild $OPERATION --flake . +else + echo "No NixOS updates found." fi -sudo nixos-rebuild $OPERATION --flake . - echo "Updating Flatpaks:" flatpak update