nix: Set profile only with certain goals

This commit is contained in:
Zhaofeng Li 2020-12-19 16:34:24 -08:00
parent 480d7ea5a1
commit d99089ad6b
2 changed files with 19 additions and 7 deletions

View file

@ -86,11 +86,13 @@ impl Host for Local {
} }
async fn activate(&mut self, profile: &StorePath, goal: DeploymentGoal) -> NixResult<()> { async fn activate(&mut self, profile: &StorePath, goal: DeploymentGoal) -> NixResult<()> {
let profile = profile.as_path().to_str().unwrap(); let profile = profile.as_path().to_str().unwrap();
Command::new("nix-env") if goal.should_switch_profile() {
.args(&["--profile", SYSTEM_PROFILE]) Command::new("nix-env")
.args(&["--set", profile]) .args(&["--profile", SYSTEM_PROFILE])
.passthrough() .args(&["--set", profile])
.await?; .passthrough()
.await?;
}
let activation_command = format!("{}/bin/switch-to-configuration", profile); let activation_command = format!("{}/bin/switch-to-configuration", profile);
Command::new(activation_command) Command::new(activation_command)
@ -133,8 +135,10 @@ impl Host for SSH {
async fn activate(&mut self, profile: &StorePath, goal: DeploymentGoal) -> NixResult<()> { async fn activate(&mut self, profile: &StorePath, goal: DeploymentGoal) -> NixResult<()> {
let profile = profile.as_path().to_str().unwrap(); let profile = profile.as_path().to_str().unwrap();
let set_profile = self.ssh(&["nix-env", "--profile", SYSTEM_PROFILE, "--set", profile]); if goal.should_switch_profile() {
self.run_command(set_profile).await?; let set_profile = self.ssh(&["nix-env", "--profile", SYSTEM_PROFILE, "--set", profile]);
self.run_command(set_profile).await?;
}
let activation_command = format!("{}/bin/switch-to-configuration", profile); let activation_command = format!("{}/bin/switch-to-configuration", profile);
let command = self.ssh(&[&activation_command, goal.as_str().unwrap()]); let command = self.ssh(&[&activation_command, goal.as_str().unwrap()]);

View file

@ -207,6 +207,14 @@ impl DeploymentGoal {
DryActivate => Some("Dry activation successful"), DryActivate => Some("Dry activation successful"),
} }
} }
pub fn should_switch_profile(&self) -> bool {
use DeploymentGoal::*;
match self {
Boot | Switch => true,
_ => false,
}
}
} }
struct NixInstantiate<'hive> { struct NixInstantiate<'hive> {