difftreelog
feat create gc root per built system
in: trunk
5 files changed
Cargo.lockdiffbeforeafterboth962 "nixlike",962 "nixlike",963 "nom",963 "nom",964 "openssh",964 "openssh",965 "rand",965 "serde",966 "serde",966 "serde_json",967 "serde_json",967 "tempfile",968 "tempfile",cmds/fleet/src/cmds/build_systems.rsdiffbeforeafterboth253253254async fn build_task(254async fn build_task(255 config: Config,255 config: Config,256 host: String,256 hostname: String,257 build_attr: &str,257 build_attr: &str,258 batch: Option<NixBuildBatch>,258 batch: Option<NixBuildBatch>,259) -> Result<PathBuf> {259) -> Result<PathBuf> {260 info!("building");260 info!("building");261 let host = config.host(&host).await?;261 let host = config.host(&hostname).await?;262 // let action = Action::from(self.subcommand.clone());262 // let action = Action::from(self.subcommand.clone());263 let nixos = host.nixos_config().await?;263 let nixos = host.nixos_config().await?;264 let drv = nix_go!(nixos.system.build[{ build_attr }]);264 let drv = nix_go!(nixos.system.build[{ build_attr }]);267 .get("out")267 .get("out")268 .ok_or_else(|| anyhow!("system build should produce \"out\" output"))?;268 .ok_or_else(|| anyhow!("system build should produce \"out\" output"))?;269270 {271 info!("adding gc root");272 let mut cmd = config.local_host().cmd("nix").await?;273 cmd.arg("build")274 .comparg(275 "--profile",276 format!(277 "/nix/var/nix/profiles/{}-{hostname}",278 config.data().gc_root_prefix279 ),280 )281 .arg(out_output);282 cmd.sudo().run_nix().await?;283 }269284270 Ok(out_output.clone())285 Ok(out_output.clone())271}286}crates/fleet-base/Cargo.tomldiffbeforeafterboth17nixlike.workspace = true17nixlike.workspace = true18nom = "7.1.3"18nom = "7.1.3"19openssh = "0.11.0"19openssh = "0.11.0"20rand = "0.8.5"20serde.workspace = true21serde.workspace = true21serde_json = "1.0.127"22serde_json = "1.0.127"22tempfile.workspace = true23tempfile.workspace = truecrates/fleet-base/src/fleetdata.rsdiffbeforeafterboth6use age::Recipient;6use age::Recipient;7use chrono::{DateTime, Utc};7use chrono::{DateTime, Utc};8use fleet_shared::SecretData;8use fleet_shared::SecretData;9use rand::{10 distributions::{Alphanumeric, DistString},11 thread_rng,12};9use serde::{de::Error, Deserialize, Serialize};13use serde::{de::Error, Deserialize, Serialize};10use serde_json::Value;14use serde_json::Value;111542 }46 }43}47}4849fn generate_gc_prefix() -> String {50 let id = Alphanumeric.sample_string(&mut thread_rng(), 8);51 format!("fleet-gc-{id}")52}445345#[derive(Serialize, Deserialize)]54#[derive(Serialize, Deserialize)]46#[serde(rename_all = "camelCase")]55#[serde(rename_all = "camelCase")]47pub struct FleetData {56pub struct FleetData {48 pub version: FleetDataVersion,57 pub version: FleetDataVersion,58 #[serde(default = "generate_gc_prefix")]59 pub gc_root_prefix: String,496050 #[serde(default)]61 #[serde(default)]51 pub hosts: BTreeMap<String, HostData>,62 pub hosts: BTreeMap<String, HostData>,modules/hosts.nixdiffbeforeafterboth16 type = str;16 type = str;17 internal = true;17 internal = true;18 };18 };19 gcRootPrefix = mkOption {20 type = str;21 internal = true;22 };19 hosts = mkOption {23 hosts = mkOption {20 type = attrsOf (submodule {24 type = attrsOf (submodule {21 options.encryptionKey = mkOption {25 options.encryptionKey = mkOption {