1
0
Fork 0

General: update nixos upgrade helper script

This commit is contained in:
Aires 2024-09-28 13:18:26 -04:00
parent 21a8933a96
commit abd2b8dfdf
4 changed files with 16 additions and 28 deletions

View file

@ -1,15 +1,13 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Wrapper script for nixos-rebuild # Wrapper script for nixos-rebuild
#set -e
# Configuration parameters # Configuration parameters
operation="switch" # The nixos-rebuild operation to use operation="switch" # The nixos-rebuild operation to use
hostname=$(hostname) # The name of the host to build hostname=$(hostname) # The name of the host to build
flakeDir="." # Path to the flake file (and optionally the hostname) flakeDir="." # Path to the flake file (and optionally the hostname)
remainingArgs="" # All remaining arguments that haven't been processed remainingArgs="" # All remaining arguments that haven't been processed
commit=true # Whether to update git (true by default) commit=true # Whether to update git (true by default)
buildHost="" # Which host to build the system on. buildHost="" # Which host to build the system on.
function usage() { function usage() {
echo "Usage: nixos-upgrade-script.sh [-o|--operation operation] [-f|--flake path-to-flake-file] [extra nixos-rebuild parameters]" echo "Usage: nixos-upgrade-script.sh [-o|--operation operation] [-f|--flake path-to-flake-file] [extra nixos-rebuild parameters]"
@ -24,14 +22,15 @@ function usage() {
} }
function run_operation { function run_operation {
echo "Full operation: nixos-rebuild $1 --flake $flakeDir#$hostname $( [ "$buildHost" != "" ] && echo "--build-host $buildHost" ) $remainingArgs" echo "Full operation: nixos-rebuild $1 --flake $flakeDir#$hostname $( [ "$buildHost" != "" ] && echo "--build-host $buildHost" ) $remainingArgs --use-remote-sudo"
nixos-rebuild $operation --flake .#$hostname $remainingArgs --use-remote-sudo
# Only request super-user permission if we're switching # Only request super-user permission if we're switching
if [[ "$1" =~ ^(switch|boot|test)$ ]]; then #if [[ "$1" =~ ^(switch|boot|test)$ ]]; then
sudo nixos-rebuild $operation --flake .#$hostname $remainingArgs # nixos-rebuild $operation --flake .#$hostname $remainingArgs --use-remote-sudo
else #else
nixos-rebuild $operation --flake .#$hostname $remainingArgs # nixos-rebuild $operation --flake .#$hostname $remainingArgs
fi #fi
} }
# Argument processing logic shamelessly stolen from https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash # Argument processing logic shamelessly stolen from https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
@ -85,11 +84,6 @@ if [ $commit = true ]; then
git push git push
fi fi
# If this is a remote build, run the build as non-sudo first
if [[ "$buildHost" != "" ]]; then
run_operation "build"
fi
run_operation $operation run_operation $operation
exit 0 exit 0

View file

@ -17,6 +17,9 @@
zellij # Terminal multiplexer zellij # Terminal multiplexer
]; ];
# Install the nos helper script
aux.system.nixos-upgrade-script.enable = true;
nixpkgs.overlays = [ nixpkgs.overlays = [
(final: _prev: { (final: _prev: {
# Allow packages from the unstable repo by using 'pkgs.unstable' # Allow packages from the unstable repo by using 'pkgs.unstable'

View file

@ -23,17 +23,7 @@ in
type = lib.types.str; type = lib.types.str;
default = "monthly"; default = "monthly";
}; };
nixos-upgrade-script = { nixos-upgrade-script.enable = lib.mkEnableOption "Installs the nos (nixos-upgrade-script) helper script.";
enable = lib.mkEnableOption "Installs the nos (nixos-upgrade-script) helper script.";
configDir = lib.mkOption {
type = lib.types.str;
description = "Path to your NixOS configuration files.";
};
user = lib.mkOption {
type = lib.types.str;
description = "The user to run the upgrade script as.";
};
};
}; };
}; };
config = { config = {

View file

@ -90,6 +90,7 @@ in
theme = "gentoo"; theme = "gentoo";
}; };
shellAliases = { shellAliases = {
nos = lib.mkIf config.aux.system.nixos-upgrade-script.enable "nixos-upgrade-script";
z = "zellij"; z = "zellij";
update = "upgrade"; update = "upgrade";
upgrade = "nh os boot --update --ask"; upgrade = "nh os boot --update --ask";