diff options
author | Maximilian Bosch | 2022-10-09 18:37:10 +0200 |
---|---|---|
committer | Maximilian Bosch | 2022-10-09 18:47:08 +0200 |
commit | 068372aad18f04122bbdb836e36c655c157ebe71 (patch) | |
tree | a32513f56334765e68c64a680f0acb6e67f0ecb5 /src/bin | |
parent | 41f15759dd8b638e7b4f299730d94d5aa46ab7eb (diff) |
Add new activation strategy `boot` as equivalent to `nixos-rebuild boot`
This can be useful when e.g. deploying a kernel update to a target host.
You usually plan a reboot (or kexec) after that to activate the new
kernel. However you don't want to wait for services to be restarted
first since these will be "restarted" anyways on the reboot. In cases
like GitLab or the Atlassian stack this actually makes a difference.
This patch changes the following things:
* If `--boot` is provided, `nix-env -p profile-to-activate --set` is
called for each deployed profile to make sure that it is activated
automatically after a reboot.
* However, the actual activation (e.g. `switch-to-configuration switch`)
is skipped. Instead:
* For NixOS, `switch-to-configuration boot` is called to set the new
profile as default in the bootloader.
* For everything else, nothing else is done. The profile is already
the new default (and thus picked up on the next boot).
Diffstat (limited to '')
-rw-r--r-- | src/bin/activate.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/bin/activate.rs b/src/bin/activate.rs index d0cfbe1..4c865f1 100644 --- a/src/bin/activate.rs +++ b/src/bin/activate.rs @@ -69,6 +69,10 @@ struct ActivateOpts { #[clap(long)] dry_activate: bool, + /// Don't activate, but update the boot loader to boot into the new profile + #[clap(long)] + boot: bool, + /// Path for any temporary files that may be needed during activation #[clap(long)] temp_path: String, @@ -363,6 +367,7 @@ pub async fn activate( confirm_timeout: u16, magic_rollback: bool, dry_activate: bool, + boot: bool, ) -> Result<(), ActivateError> { if !dry_activate { info!("Activating profile"); @@ -396,6 +401,7 @@ pub async fn activate( let activate_status = match Command::new(format!("{}/deploy-rs-activate", activation_location)) .env("PROFILE", activation_location) .env("DRY_ACTIVATE", if dry_activate { "1" } else { "0" }) + .env("BOOT", if boot { "1" } else { "0" }) .current_dir(activation_location) .status() .await @@ -425,7 +431,7 @@ pub async fn activate( info!("Activation succeeded!"); } - if magic_rollback { + if magic_rollback && !boot { info!("Magic rollback is enabled, setting up confirmation hook..."); match activation_confirmation(profile_path.clone(), temp_path, confirm_timeout, closure) @@ -479,6 +485,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { activate_opts.confirm_timeout, activate_opts.magic_rollback, activate_opts.dry_activate, + activate_opts.boot, ) .await .map_err(|x| Box::new(x) as Box<dyn std::error::Error>), |