difftreelog
feat test/boot/switch actions
in: trunk
1 file changed
src/cmds/build_systems.rsdiffbeforeafterboth14 /// Hosts to skip14 /// Hosts to skip15 #[clap(long, number_of_values = 1)]15 #[clap(long, number_of_values = 1)]16 skip: Vec<String>,16 skip: Vec<String>,17 /// Host, which should be threaten as localhost18 #[clap(long, env = "FLEET_LOCALHOST")]19 localhost: Option<String>,17 #[clap(subcommand)]20 #[clap(subcommand)]18 subcommand: Option<Subcommand>,21 subcommand: Option<Subcommand>,19}22}27 /// test + boot30 /// test + boot28 Switch,31 Switch,29}32}33impl Subcommand {34 fn should_switch_profile(&self) -> bool {35 matches!(self, Self::Test | Self::Switch)36 }37 fn name(&self) -> &'static str {38 match self {39 Self::Test => "test",40 Self::Boot => "boot",41 Self::Switch => "switch",42 }43 }44}304531impl BuildSystems {46impl BuildSystems {32 pub fn run(self) -> Result<()> {47 pub fn run(self) -> Result<()> {39 warn!("Skipping host {}", host);54 warn!("Skipping host {}", host);40 continue;55 continue;41 }56 }57 let is_local = Some(host) == self.localhost.as_ref();42 info!("Building host {}", host);58 info!("Building host {}", host);43 let built = tempfile::tempdir()?;59 let built = {60 let dir = tempfile::tempdir()?;61 dir.path().to_owned()62 };6344 Command::new("nix")64 Command::new("nix")45 .inherit_stdio()65 .args(&["build", "--impure", "--no-link", "--out-link"])46 .arg("build")47 .arg(format!(48 "{}.{}.config.system.build.toplevel",49 SYSTEMS_ATTRIBUTE, host,50 ))51 .arg("--no-link")52 .arg("--out-link")66 .arg(&built)53 .arg(built.path())67 .arg(format!(68 "{}.{}.config.system.build.toplevel",69 SYSTEMS_ATTRIBUTE, host,70 ))54 .arg("--impure")71 .env("SECRET_DATA", data.clone())55 .env("SECRET_DATA", data.clone())72 .inherit_stdio()56 .run()?;73 .run()?;57 info!("Uploading system closure");58 let full_path = std::fs::canonicalize(built.path())?;74 let built = std::fs::canonicalize(built)?;59 info!("{:?}", full_path);75 info!("Built closure: {:?}", built);76 if !is_local {77 info!("Uploading system closure");60 Command::new("nix")78 Command::new("nix")61 .inherit_stdio()79 .args(&["copy", "--to"])62 .arg("copy")80 .arg(format!("ssh://root@{}", host))63 .arg(full_path)81 .arg(&built)64 .arg("--to")82 .inherit_stdio()65 .arg(format!("ssh://root@{}", host))83 .run()?;66 .run()?;84 }67 match self.subcommand {85 if let Some(subcommand) = &self.subcommand {68 Some(Subcommand::Test) => {86 if subcommand.should_switch_profile() {69 info!("Setting system to test")87 info!("Switching generation");88 if !is_local {89 Command::ssh_on(host, "nix-env")90 } else {91 Command::new("nix-env")92 }93 .args(&["-p", "/nix/var/nix/profiles/system", "--set"])94 .arg(&built)95 .inherit_stdio()96 .run()?;70 }97 }71 Some(Subcommand::Boot) => {72 info!("Setting system to switch on boot")98 info!("Executing activation script");73 }99 let mut switch_script = built.clone();74 Some(Subcommand::Switch) => {100 switch_script.push("bin");101 switch_script.push("switch-to-configuration");75 info!("Switching to configuration")102 info!("{:?}", switch_script);76 }77 _ => {}103 if !is_local {104 Command::ssh_on(host, "sudo")105 } else {106 Command::new("sudo")107 }108 .arg(switch_script)109 .arg(subcommand.name())110 .inherit_stdio()111 .run()?;78 }112 }79 }113 }80 Ok(())114 Ok(())