use std::ffi::OsStr; use std::ffi::OsString; use std::path::Path; use std::process::Stdio; use tokio::process::Command; use crate::Result; use crate::database::db_handle::DbHandle; use super::RunningUpdate; use super::RunningVerify; use super::running_build::RunningBuild; pub(crate) async fn nixos_build_target( db_handle: &DbHandle, build_path: B, flake_path: F, attr: A, target_name: TN, build_id: i64, ) -> Result<()> where B: AsRef, F: AsRef, A: AsRef, TN: AsRef, { let reference = { let path = AsRef::::as_ref(flake_path.as_ref()); let attr = attr.as_ref(); let mut reference = OsString::with_capacity(path.len() + attr.len() + 1); reference.push(path); reference.push("#"); reference.push(attr); reference }; let mut command = Command::new("nix"); command.current_dir(build_path); command.stdout(Stdio::piped()); command.stderr(Stdio::piped()); command.stdin(Stdio::null()); command.args([ "build", "--show-trace", "--max-jobs", "1", "--repair", "--log-format", "internal-json", "-vvvvvvvvvvv", "--keep-going", ]); command.arg(reference); command.kill_on_drop(true); let child = command.spawn()?; let mut running_build = RunningBuild::new(db_handle, build_id)?; running_build.run_to_completion(child, target_name).await?; Ok(()) } pub(crate) async fn nix_flake_update(flake_path: F) -> Result<()> where F: AsRef, { let mut command = Command::new("nix"); command.current_dir(flake_path); command.stdout(Stdio::piped()); command.stderr(Stdio::piped()); command.stdin(Stdio::null()); command.args([ "flake", "update", "--log-format", "internal-json", "-vvvvvvvvvvv", ]); command.kill_on_drop(true); let child = command.spawn()?; let mut running_update = RunningUpdate::new()?; running_update.run_to_completion(child).await?; Ok(()) } pub(crate) async fn nix_store_verify_repair_check_contents() -> Result<()> { let mut command = Command::new("nix-store"); command.stdout(Stdio::piped()); command.stderr(Stdio::piped()); command.stdin(Stdio::null()); command.args([ "--verify", "--check-contents", "--repair", "--log-format", "internal-json", "-vvvvvvvvvvv", ]); command.kill_on_drop(true); let child = command.spawn()?; let mut running_verify = RunningVerify::new()?; running_verify.run_to_completion(child).await?; Ok(()) }