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

View file

@ -22,6 +22,15 @@ in
type = lib.types.str; type = lib.types.str;
description = "How frequently to run updates. See systemd.timer(5) and systemd.time(7) for configuration details."; 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 { persistent = lib.mkOption {
default = true; default = true;
type = lib.types.bool; type = lib.types.bool;
@ -57,10 +66,10 @@ in
path = config.aux.system.corePackages; path = config.aux.system.corePackages;
unitConfig.RequiresMountsFor = cfg.configDir; unitConfig.RequiresMountsFor = cfg.configDir;
script = lib.strings.concatStrings [ 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.configDir != "") "--flake ${cfg.configDir} ").content
(lib.mkIf (cfg.user != "") "--user ${cfg.user} ").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 (lib.mkIf (cfg.extraFlags != "") cfg.extraFlags).content
]; ];
}; };