manager: add update_meta_inputs tool to update flake.lock on demand (closes #235)

This commit is contained in:
damocles 2026-05-22 01:31:26 +02:00 committed by Mara
parent 15e44955a8
commit 597e4ba03a
5 changed files with 76 additions and 8 deletions

View file

@ -311,6 +311,22 @@ async fn dispatch(req: &ManagerRequest, coord: &Arc<Coordinator>) -> ManagerResp
},
}
}
ManagerRequest::UpdateMetaInputs { inputs } => {
let label = if inputs.is_empty() {
"all inputs".to_string()
} else {
inputs.join(", ")
};
tracing::info!(%label, "manager: update_meta_inputs");
// Treat empty list as "update all" by passing the full list
// to lock_update; it calls bare `nix flake update` when empty.
match crate::meta::lock_update(inputs).await {
Ok(()) => ManagerResponse::Ok,
Err(e) => ManagerResponse::Err {
message: format!("update_meta_inputs({label}): {e:#}"),
},
}
}
ManagerRequest::Ask {
question,
options,

View file

@ -190,14 +190,12 @@ pub async fn lock_update_for_rebuild(name: &str) -> Result<()> {
/// Used by the dashboard's "update meta inputs" form so the
/// operator can bulk-bump `hyperhive` + selected agents in one
/// shot. Each input name is passed verbatim to
/// `nix flake update`; the caller is responsible for picking
/// real input keys (e.g. via `inputs_view()` snapshotted from
/// the lock file).
#[allow(dead_code)] // wired up by dashboard handler in the same commit
/// Run `nix flake update [inputs...]` on the meta flake and commit the
/// resulting lock changes. When `inputs` is empty, updates ALL inputs
/// (bare `nix flake update`). The caller is responsible for picking
/// real input keys (e.g. via `inputs_view()` snapshotted from the lock
/// file) when targeting specific inputs.
pub async fn lock_update(inputs: &[String]) -> Result<()> {
if inputs.is_empty() {
return Ok(());
}
let _guard = META_LOCK.lock().await;
let dir = meta_dir();
let mut args: Vec<&str> = vec!["flake", "update"];
@ -209,7 +207,9 @@ pub async fn lock_update(inputs: &[String]) -> Result<()> {
return Ok(());
}
git(&dir, &["add", "flake.lock"]).await?;
let msg = if inputs.len() == 1 {
let msg = if inputs.is_empty() {
"lock update: all inputs".to_string()
} else if inputs.len() == 1 {
format!("lock update: {}", inputs[0])
} else {
format!("lock update: {}", inputs.join(", "))