2026-02-14 19:20:52 -05:00
|
|
|
use std::ffi::OsStr;
|
|
|
|
|
use std::ffi::OsString;
|
|
|
|
|
use std::path::Path;
|
2026-02-15 01:45:42 -05:00
|
|
|
use std::process::Stdio;
|
2026-02-14 19:20:52 -05:00
|
|
|
|
|
|
|
|
use tokio::process::Command;
|
|
|
|
|
|
2026-02-15 01:45:42 -05:00
|
|
|
use crate::Result;
|
|
|
|
|
use crate::database::db_handle::DbHandle;
|
2026-02-14 19:20:52 -05:00
|
|
|
|
2026-06-25 18:25:02 -04:00
|
|
|
use super::RunningUpdate;
|
2026-07-31 19:26:46 -04:00
|
|
|
use super::RunningVerify;
|
2026-02-16 20:06:46 -05:00
|
|
|
use super::running_build::RunningBuild;
|
|
|
|
|
|
2026-02-16 20:42:03 -05:00
|
|
|
pub(crate) async fn nixos_build_target<B, F, A, TN>(
|
2026-02-15 01:45:42 -05:00
|
|
|
db_handle: &DbHandle,
|
2026-02-14 19:20:52 -05:00
|
|
|
build_path: B,
|
|
|
|
|
flake_path: F,
|
|
|
|
|
attr: A,
|
2026-02-16 20:42:03 -05:00
|
|
|
target_name: TN,
|
2026-07-24 20:29:41 -04:00
|
|
|
build_id: i64,
|
2026-02-15 01:45:42 -05:00
|
|
|
) -> Result<()>
|
2026-02-14 19:20:52 -05:00
|
|
|
where
|
|
|
|
|
B: AsRef<Path>,
|
|
|
|
|
F: AsRef<Path>,
|
|
|
|
|
A: AsRef<str>,
|
2026-02-16 20:42:03 -05:00
|
|
|
TN: AsRef<str>,
|
2026-02-14 19:20:52 -05:00
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-19 18:39:01 -05:00
|
|
|
let mut command = Command::new("nix");
|
2026-02-14 19:20:52 -05:00
|
|
|
command.current_dir(build_path);
|
2026-02-15 01:45:42 -05:00
|
|
|
command.stdout(Stdio::piped());
|
|
|
|
|
command.stderr(Stdio::piped());
|
|
|
|
|
command.stdin(Stdio::null());
|
2026-02-14 22:15:09 -05:00
|
|
|
command.args([
|
2026-02-14 19:20:52 -05:00
|
|
|
"build",
|
|
|
|
|
"--show-trace",
|
|
|
|
|
"--max-jobs",
|
|
|
|
|
"1",
|
2026-04-02 17:33:56 -04:00
|
|
|
"--repair",
|
2026-02-14 19:20:52 -05:00
|
|
|
"--log-format",
|
|
|
|
|
"internal-json",
|
2026-02-17 22:49:42 -05:00
|
|
|
"-vvvvvvvvvvv",
|
2026-02-15 01:45:42 -05:00
|
|
|
"--keep-going",
|
2026-02-14 19:20:52 -05:00
|
|
|
]);
|
|
|
|
|
command.arg(reference);
|
|
|
|
|
command.kill_on_drop(true);
|
|
|
|
|
|
2026-02-16 20:06:46 -05:00
|
|
|
let child = command.spawn()?;
|
2026-02-15 01:45:42 -05:00
|
|
|
|
2026-07-24 20:29:41 -04:00
|
|
|
let mut running_build = RunningBuild::new(db_handle, build_id)?;
|
2026-02-16 20:42:03 -05:00
|
|
|
running_build.run_to_completion(child, target_name).await?;
|
2026-02-14 19:20:52 -05:00
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
2026-06-25 18:25:02 -04:00
|
|
|
|
|
|
|
|
pub(crate) async fn nix_flake_update<F>(flake_path: F) -> Result<()>
|
|
|
|
|
where
|
|
|
|
|
F: AsRef<Path>,
|
|
|
|
|
{
|
|
|
|
|
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(())
|
|
|
|
|
}
|
2026-07-31 19:26:46 -04:00
|
|
|
|
|
|
|
|
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(())
|
|
|
|
|
}
|