Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
elif [[ "''${BOOT:-}" == "1" ]]
then
${customSelf.boot or "echo ${final.writeScript "activate" activate}"}
elif [[ "''${TEST:-}" == "1" ]]
then
${customSelf.test or "echo ${final.writeScript "activate" activate}"}
else
${activate}
fi
Expand All @@ -92,6 +95,7 @@
(custom // {
dryActivate = "$PROFILE/bin/switch-to-configuration dry-activate";
boot = "$PROFILE/bin/switch-to-configuration boot";
test = "$PROFILE/bin/switch-to-configuration test";
})
base.config.system.build.toplevel
''
Expand Down
7 changes: 7 additions & 0 deletions src/bin/activate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ struct ActivateOpts {
#[arg(long)]
boot: bool,

/// Activate the configuration, but don't update the boot loader
#[arg(long)]
test: bool,

/// Path for any temporary files that may be needed during activation
#[arg(long)]
temp_path: PathBuf,
Expand Down Expand Up @@ -390,6 +394,7 @@ pub async fn activate(
magic_rollback: bool,
dry_activate: bool,
boot: bool,
test: bool,
) -> Result<(), ActivateError> {
if !dry_activate {
info!("Activating profile");
Expand Down Expand Up @@ -424,6 +429,7 @@ pub async fn activate(
.env("PROFILE", activation_location)
.env("DRY_ACTIVATE", if dry_activate { "1" } else { "0" })
.env("BOOT", if boot { "1" } else { "0" })
.env("TEST", if test { "1" } else { "0" })
.current_dir(activation_location)
.status()
.await
Expand Down Expand Up @@ -561,6 +567,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
activate_opts.magic_rollback,
activate_opts.dry_activate,
activate_opts.boot,
activate_opts.test,
)
.await
.map_err(|x| Box::new(x) as Box<dyn std::error::Error>),
Expand Down
16 changes: 9 additions & 7 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,14 @@ pub struct Opts {
#[arg(long)]
temp_path: Option<PathBuf>,
/// Show what will be activated on the machines
#[arg(long)]
#[arg(long, conflicts_with_all = ["test", "boot"])]
dry_activate: bool,
/// Don't activate, but update the boot loader to boot into the new profile
#[arg(long)]
#[arg(long, conflicts_with_all = ["test", "dry_activate"])]
boot: bool,
/// Activate the configuration, but don't update the boot loader
#[arg(long, conflicts_with_all = ["boot", "dry_activate"])]
test: bool,
/// Revoke all previously succeeded deploys when deploying multiple profiles
#[arg(long)]
rollback_succeeded: Option<bool>,
Expand Down Expand Up @@ -427,6 +430,7 @@ async fn run_deploy(
debug_logs: bool,
dry_activate: bool,
boot: bool,
test: bool,
log_dir: &Option<String>,
rollback_succeeded: bool,
) -> Result<(), RunDeployError> {
Expand Down Expand Up @@ -611,7 +615,8 @@ async fn run_deploy(
// Rollbacks adhere to the global seeting to auto_rollback and secondary
// the profile's configuration
for (_, deploy_data, deploy_defs) in &parts {
if let Err(e) = deploy::deploy::deploy_profile(deploy_data, deploy_defs, dry_activate, boot).await
if let Err(e) =
deploy::deploy::deploy_profile(deploy_data, deploy_defs, dry_activate, boot, test).await
{
error!("{}", e);
if dry_activate {
Expand Down Expand Up @@ -673,10 +678,6 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
&deploy::LoggerType::Deploy,
)?;

if opts.dry_activate && opts.boot {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this was intentionally not handled in clap; if so, I can revert that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a good change. I prefer the solution you are taking.

error!("Cannot use both --dry-activate & --boot!");
}

let deploys = opts
.clone()
.targets
Expand Down Expand Up @@ -746,6 +747,7 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
opts.debug_logs,
opts.dry_activate,
opts.boot,
opts.test,
&opts.log_dir,
opts.rollback_succeeded.unwrap_or(true),
)
Expand Down
9 changes: 9 additions & 0 deletions src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct ActivateCommandData<'a> {
log_dir: Option<&'a str>,
dry_activate: bool,
boot: bool,
test: bool,
}

fn build_activate_command(data: &ActivateCommandData) -> String {
Expand Down Expand Up @@ -75,6 +76,10 @@ fn build_activate_command(data: &ActivateCommandData) -> String {
self_activate_command = format!("{} --boot", self_activate_command);
}

if data.test {
self_activate_command = format!("{} --test", self_activate_command);
}

if let Some(sudo_cmd) = &data.sudo {
self_activate_command = format!("{} {}", sudo_cmd, self_activate_command);
}
Expand All @@ -92,6 +97,7 @@ fn test_activation_command_builder() {
let auto_rollback = true;
let dry_activate = false;
let boot = false;
let test = false;
let temp_path = Path::new("/tmp");
let confirm_timeout = 30;
let magic_rollback = true;
Expand All @@ -111,6 +117,7 @@ fn test_activation_command_builder() {
log_dir,
dry_activate,
boot,
test,
}),
"sudo -u test /nix/store/blah/etc/activate-rs --debug-logs --log-dir /tmp/something.txt activate '/nix/store/blah/etc' --profile-path '/blah/profiles/test' --temp-path '/tmp' --confirm-timeout 30 --magic-rollback --auto-rollback"
.to_string(),
Expand Down Expand Up @@ -354,6 +361,7 @@ pub async fn deploy_profile(
deploy_defs: &super::DeployDefs,
dry_activate: bool,
boot: bool,
test: bool,
) -> Result<(), DeployProfileError> {
if !dry_activate {
info!(
Expand Down Expand Up @@ -387,6 +395,7 @@ pub async fn deploy_profile(
log_dir: deploy_data.log_dir,
dry_activate,
boot,
test,
});

debug!("Constructed activation command: {}", self_activate_command);
Expand Down