diff --git a/bin/nixos-upgrade-script.sh b/bin/nixos-upgrade-script.sh index fee4f20..6a79295 100755 --- a/bin/nixos-upgrade-script.sh +++ b/bin/nixos-upgrade-script.sh @@ -3,11 +3,11 @@ # Configuration parameters operation="switch" # The nixos-rebuild operation to use -hostname=$(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. remainingArgs="" # All remaining arguments that haven't been processed update=true # Whether to update git (true by default) -user=$(whoami) # Which user account to use for git commands. +user=$(/run/current-system/sw/bin/whoami) # Which user account to use for git commands. function usage() { echo "nixos-rebuild Operations Script (NOS) updates your system and your flake.lock file by pulling the latest versions." @@ -87,6 +87,6 @@ fi options="--flake $flakeDir $remainingArgs --use-remote-sudo --log-format multiline-with-logs" echo "Running this operation: nixos-rebuild $operation $options" -nixos-rebuild $operation $options +/run/current-system/sw/bin/nixos-rebuild $operation $options exit 0 diff --git a/hosts/Khanda/default.nix b/hosts/Khanda/default.nix index d021fd0..ffada57 100644 --- a/hosts/Khanda/default.nix +++ b/hosts/Khanda/default.nix @@ -1,4 +1,4 @@ -{ ... }: +{ config, ... }: let # Do not change this value! This tracks when NixOS was installed on your system. @@ -48,7 +48,13 @@ in retentionPeriod = "14d"; services = { - autoUpgrade.enable = false; + autoUpgrade = { + enable = true; + extraFlags = "--build-host hevana"; + configDir = config.secrets.nixConfigFolder; + onCalendar = "weekly"; + user = config.users.users.aires.name; + }; virtualization.enable = true; }; diff --git a/modules/services/autoupgrade.nix b/modules/services/autoupgrade.nix index d6eb029..1a607f5 100644 --- a/modules/services/autoupgrade.nix +++ b/modules/services/autoupgrade.nix @@ -12,6 +12,10 @@ in type = lib.types.str; description = "Path where your NixOS configuration files are stored."; }; + extraFlags = lib.mkOption { + type = lib.types.str; + description = "Extra flags to pass to nixos-rebuild."; + }; onCalendar = lib.mkOption { default = "daily"; type = lib.types.str; @@ -53,9 +57,10 @@ in unitConfig.RequiresMountsFor = cfg.configDir; script = lib.strings.concatStrings [ "/run/current-system/sw/bin/nixos-upgrade-script --operation switch " - (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.configDir) "--flake ${cfg.configDir} ").content + (lib.mkIf (cfg.user) "--user ${cfg.user} ").content + (lib.mkIf (!cfg.pushUpdates) "--no-update ").content + (lib.mkIf (cfg.extraFlags) cfg.extraFlags).content ]; }; timers."nixos-upgrade" = {