1
0
Fork 0

Bin: invert update flag; add operation option to autoupgrade module

This commit is contained in:
Aires 2024-10-02 14:02:58 -04:00
parent 3a7a4a1b2d
commit 70ee697cb8
2 changed files with 21 additions and 12 deletions

View file

@ -2,12 +2,12 @@
# Wrapper script for nixos-rebuild
# Configuration parameters
operation="switch" # The nixos-rebuild operation to use
hostname=$(/run/current-system/sw/bin/hostname) # The name of the host to build
flakeDir="${FLAKE_DIR}" # Path to the flake file (and optionally the hostname). Defaults to the FLAKE_DIR environment variable.
remainingArgs="" # All remaining arguments that haven't been processed
update=true # Whether to update git (true by default)
user=$(/run/current-system/sw/bin/whoami) # Which user account to use for git commands.
operation="switch" # The nixos-rebuild operation to use
hostname=$(/run/current-system/sw/bin/hostname) # The name of the host to build
flakeDir="${FLAKE_DIR}" # Path to the flake file (and optionally the hostname). Defaults to the FLAKE_DIR environment variable.
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)
remainingArgs="" # All remaining arguments that haven't yet been processed (will be passed to nixos-rebuild)
function usage() {
echo "nixos-rebuild Operations Script (NOS) updates your system and your flake.lock file by pulling the latest versions."
@ -23,7 +23,7 @@ function usage() {
echo " -h, --help Show this help screen."
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 " -n, --no-update Don't update and commit the lock file."
echo " -U, --update Update and commit flake.lock."
echo " -u, --user Which user account to run git commands under."
echo ""
exit 2
@ -38,8 +38,8 @@ while [[ $# -gt 0 ]]; do
shift
shift
;;
--no-update|--no-upgrade|-n)
update=false
--update|--upgrade|-U)
update=true
shift
;;
--operation|-o)
@ -85,6 +85,6 @@ fi
options="--flake $flakeDir $remainingArgs --use-remote-sudo --log-format multiline-with-logs"
echo "Running this operation: nixos-rebuild $operation $options"
/run/current-system/sw/bin/nixos-rebuild $operation $options
/run/wrappers/bin/sudo -u root /run/current-system/sw/bin/nixos-rebuild $operation $options
exit 0

View file

@ -22,6 +22,15 @@ in
type = lib.types.str;
description = "How frequently to run updates. See systemd.timer(5) and systemd.time(7) for configuration details.";
};
operation = lib.mkOption {
type = lib.types.enum [
"boot"
"switch"
"test"
];
default = "switch";
description = "Which `nixos-rebuild` operation to perform. Defaults to `switch`.";
};
persistent = lib.mkOption {
default = true;
type = lib.types.bool;
@ -57,10 +66,10 @@ in
path = config.aux.system.corePackages;
unitConfig.RequiresMountsFor = cfg.configDir;
script = lib.strings.concatStrings [
"/run/current-system/sw/bin/nixos-upgrade-script --operation switch "
"/run/current-system/sw/bin/nixos-upgrade-script --operation ${cfg.operation} "
(lib.mkIf (cfg.configDir != "") "--flake ${cfg.configDir} ").content
(lib.mkIf (cfg.user != "") "--user ${cfg.user} ").content
(lib.mkIf (!cfg.pushUpdates) "--no-update ").content
(lib.mkIf (cfg.pushUpdates) "--update ").content
(lib.mkIf (cfg.extraFlags != "") cfg.extraFlags).content
];
};