From 70ee697cb8b1006732bde53a6d323fb460e320fe Mon Sep 17 00:00:00 2001 From: Andre Date: Wed, 2 Oct 2024 14:02:58 -0400 Subject: [PATCH] Bin: invert update flag; add operation option to autoupgrade module --- bin/nixos-upgrade-script.sh | 20 ++++++++++---------- modules/services/autoupgrade.nix | 13 +++++++++++-- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/bin/nixos-upgrade-script.sh b/bin/nixos-upgrade-script.sh index 2b1dbb9..1447d6c 100755 --- a/bin/nixos-upgrade-script.sh +++ b/bin/nixos-upgrade-script.sh @@ -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 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 diff --git a/modules/services/autoupgrade.nix b/modules/services/autoupgrade.nix index bca52aa..00b7773 100644 --- a/modules/services/autoupgrade.nix +++ b/modules/services/autoupgrade.nix @@ -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 ]; };