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": {
"lastModified": 1711625603,
"narHash": "sha256-W+9dfqA9bqUIBV5u7jaIARAzMe3kTq/Hp2SpSVXKRQw=",
"lastModified": 1711915616,
"narHash": "sha256-co6LoFA+j6BZEeJNSR8nZ4oOort5qYPskjrDHBaJgmo=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "c0ef0dab55611c676ad7539bf4e41b3ec6fa87d2",
"rev": "820be197ccf3adaad9a8856ef255c13b6cc561a6",
"type": "github"
},
"original": {

View file

@ -9,7 +9,7 @@ let
};
# 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{
imports = [
../../modules

View file

@ -3,10 +3,36 @@
# Inspiration: https://blog.tjll.net/previewing-nixos-system-updates/
set -e
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
OPERATION=$1
fi
function usage() {
echo "Usage: nixos-upgrade.sh [ -y | --auto-accept ] [-o | --operation]"
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"
@ -16,9 +42,16 @@ nixos-rebuild build --flake .
echo "Updates to apply:"
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 ) sudo nixos-rebuild $OPERATION --flake .;;
n|N|no ) echo "Upgrade cancelled.";;
* ) echo "Invalid option. Upgrade cancelled.";;
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 .
echo "Updating Flatpaks:"
flatpak update