59 lines
1.5 KiB
Rust
59 lines
1.5 KiB
Rust
|
|
use std::ffi::OsStr;
|
||
|
|
use std::ffi::OsString;
|
||
|
|
use std::path::Path;
|
||
|
|
|
||
|
|
use tokio::process::Command;
|
||
|
|
|
||
|
|
use crate::error::CustomError;
|
||
|
|
|
||
|
|
pub(crate) async fn nixos_build_target<B, F, A>(
|
||
|
|
build_path: B,
|
||
|
|
flake_path: F,
|
||
|
|
attr: A,
|
||
|
|
) -> Result<(), CustomError>
|
||
|
|
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.args(&[
|
||
|
|
"build",
|
||
|
|
"--show-trace",
|
||
|
|
"--sudo",
|
||
|
|
"--max-jobs",
|
||
|
|
"1",
|
||
|
|
"--log-format",
|
||
|
|
"internal-json",
|
||
|
|
"-v",
|
||
|
|
]);
|
||
|
|
command.arg("--flake");
|
||
|
|
command.arg(reference);
|
||
|
|
command.kill_on_drop(true);
|
||
|
|
|
||
|
|
let mut child = command.spawn()?;
|
||
|
|
let status = child.wait().await?;
|
||
|
|
if !status.success() {
|
||
|
|
return Err("Nixos rebuild failed.".into());
|
||
|
|
}
|
||
|
|
|
||
|
|
// tokio::spawn(async move {
|
||
|
|
// let status = child.wait().await.expect("mpv encountered an error");
|
||
|
|
// println!("mpv status was: {}", status);
|
||
|
|
// });
|
||
|
|
|
||
|
|
Ok(())
|
||
|
|
}
|