1
0
Fork 0

Fix issues with nixos-upgrade.sh

This commit is contained in:
Aires 2024-04-01 09:36:52 -04:00
parent 0d494a6b1a
commit 04fb980753
3 changed files with 46 additions and 13 deletions

View file

@ -117,11 +117,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1711625603, "lastModified": 1711915616,
"narHash": "sha256-W+9dfqA9bqUIBV5u7jaIARAzMe3kTq/Hp2SpSVXKRQw=", "narHash": "sha256-co6LoFA+j6BZEeJNSR8nZ4oOort5qYPskjrDHBaJgmo=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "c0ef0dab55611c676ad7539bf4e41b3ec6fa87d2", "rev": "820be197ccf3adaad9a8856ef255c13b6cc561a6",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -9,7 +9,7 @@ let
}; };
# Install upgrade script # Install upgrade script
nixos-upgrade = pkgs.writeShellScriptBin "start-haven" (builtins.readFile ./nixos-upgrade.sh); nixos-upgrade = pkgs.writeShellScriptBin "nixos-upgrade" (builtins.readFile ./nixos-upgrade.sh);
in{ in{
imports = [ imports = [
../../modules ../../modules

View file

@ -3,10 +3,36 @@
# Inspiration: https://blog.tjll.net/previewing-nixos-system-updates/ # Inspiration: https://blog.tjll.net/previewing-nixos-system-updates/
set -e set -e
OPERATION="boot" # Which update method to use. Defaults to "boot", which applies updates on reboot. OPERATION="boot" # Which update method to use. Defaults to "boot", which applies updates on reboot.
AUTOACCEPT=false # Whether to automatically apply the update or ask for permission.
if ! [ -z "$1" ]; then function usage() {
OPERATION=$1 echo "Usage: nixos-upgrade.sh [ -y | --auto-accept ] [-o | --operation]"
fi echo "Options:"
echo " -h | --help Show this help screen."
echo " -y | --auto-accept Automatically approve pending changes."
echo " -o | --operation Which update operation to perform (switch, boot, etc.). Defaults to boot."
exit 2
}
while [[ $# -gt 0 ]]; do
case "$1" in
-y|-Y|--auto-accept)
AUTOACCEPT=true
shift
;;
-o|-O|--operation)
OPERATION=$2
shift
;;
-h|--help)
usage
shift
;;
*)
break
;;
esac
done
echo "Using installation mode: $OPERATION" echo "Using installation mode: $OPERATION"
@ -16,9 +42,16 @@ nixos-rebuild build --flake .
echo "Updates to apply:" echo "Updates to apply:"
nix store diff-closures /run/current-system ./result | awk '/[0-9] →|→ [0-9]/ && !/nixos/' || echo nix store diff-closures /run/current-system ./result | awk '/[0-9] →|→ [0-9]/ && !/nixos/' || echo
read -p "Continue with upgrade (y/n) ? " choice if [ $AUTOACCEPT == false ]; then
case "$choice" in read -p "Continue with upgrade (y/n) ? " choice
y|Y|yes ) sudo nixos-rebuild $OPERATION --flake .;; case "$choice" in
n|N|no ) echo "Upgrade cancelled.";; y|Y|yes ) echo "Running nixos-rebuild $OPERATION :";;
* ) echo "Invalid option. Upgrade cancelled.";; n|N|no ) echo "Upgrade cancelled." && exit;;
esac * ) echo "Invalid option. Upgrade cancelled." && exit;;
esac
fi
sudo nixos-rebuild $OPERATION --flake .
echo "Updating Flatpaks:"
flatpak update