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::running_build::RunningBuild; pub(crate) async fn nixos_build_target( db_handle: &DbHandle, build_path: B, flake_path: F, attr: A, target_name: TN, ) -> 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)?; running_build.run_to_completion(child, target_name).await?; Ok(()) }