62 lines
1.5 KiB
Rust
62 lines
1.5 KiB
Rust
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<B, F, A>(
|
|
db_handle: &DbHandle,
|
|
build_path: B,
|
|
flake_path: F,
|
|
attr: A,
|
|
) -> Result<()>
|
|
where
|
|
B: AsRef<Path>,
|
|
F: AsRef<Path>,
|
|
A: AsRef<str>,
|
|
{
|
|
let reference = {
|
|
let path = AsRef::<OsStr>::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
|
|
};
|
|
|
|
// nixos-rebuild build --show-trace --sudo --max-jobs "$JOBS" --flake "$DIR/../../#odo" --log-format internal-json -v "${@}"
|
|
let mut command = Command::new("nixos-rebuild");
|
|
command.current_dir(build_path);
|
|
command.stdout(Stdio::piped());
|
|
command.stderr(Stdio::piped());
|
|
command.stdin(Stdio::null());
|
|
command.args([
|
|
"build",
|
|
"--show-trace",
|
|
"--sudo",
|
|
"--max-jobs",
|
|
"1",
|
|
"--log-format",
|
|
"internal-json",
|
|
"-v",
|
|
"--keep-going",
|
|
]);
|
|
command.arg("--flake");
|
|
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).await?;
|
|
|
|
Ok(())
|
|
}
|