refactor(#2285): inline remaining 1:1 path wrappers (meta_dir, marker fns, host_conf_path)
This commit is contained in:
parent
cfb84b420a
commit
556a213320
11 changed files with 39 additions and 72 deletions
|
|
@ -4,7 +4,7 @@
|
|||
//! `finalize_deploy` / `abort_deploy`, `lock_update_hyperhive`):
|
||||
//! `docs/approvals.md::Meta flake`.
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::{Context, Result, bail};
|
||||
use tokio::process::Command;
|
||||
|
|
@ -56,11 +56,6 @@ pub struct AgentSpec {
|
|||
pub port: u16,
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn meta_dir() -> PathBuf {
|
||||
crate::paths::meta_root()
|
||||
}
|
||||
|
||||
/// Idempotently reconcile the meta repo with the current agent set.
|
||||
/// First call inits the git repo, runs `nix flake lock`, and lands a
|
||||
/// seed commit. Subsequent calls only touch `flake.nix` when the
|
||||
|
|
@ -68,7 +63,7 @@ pub fn meta_dir() -> PathBuf {
|
|||
/// no-op.
|
||||
pub async fn sync_agents(hive: &HiveEnv, agents: &[AgentSpec]) -> Result<()> {
|
||||
let _guard = META_LOCK.lock().await;
|
||||
let dir = meta_dir();
|
||||
let dir = crate::paths::meta_root();
|
||||
std::fs::create_dir_all(&dir).with_context(|| format!("create {}", dir.display()))?;
|
||||
|
||||
let new_flake = render_flake(
|
||||
|
|
@ -241,7 +236,7 @@ pub async fn sync_agents(hive: &HiveEnv, agents: &[AgentSpec]) -> Result<()> {
|
|||
/// meta history only carries successful deploys.
|
||||
pub async fn prepare_deploy(name: &str) -> Result<()> {
|
||||
let _guard = META_LOCK.lock().await;
|
||||
let dir = meta_dir();
|
||||
let dir = crate::paths::meta_root();
|
||||
let input = format!("agent-{name}");
|
||||
nix(&dir, &["flake", "update", &input]).await?;
|
||||
// Stage the new lock — git+file://'s dirty-tree fetcher reads
|
||||
|
|
@ -255,7 +250,7 @@ pub async fn prepare_deploy(name: &str) -> Result<()> {
|
|||
/// place (nothing staged → nothing to commit).
|
||||
pub async fn finalize_deploy(name: &str, sha: &str, tag: &str) -> Result<()> {
|
||||
let _guard = META_LOCK.lock().await;
|
||||
let dir = meta_dir();
|
||||
let dir = crate::paths::meta_root();
|
||||
if !paths_dirty(&dir, &["flake.lock"]).await? {
|
||||
return Ok(());
|
||||
}
|
||||
|
|
@ -273,7 +268,7 @@ pub async fn finalize_deploy(name: &str, sha: &str, tag: &str) -> Result<()> {
|
|||
/// captured in `applied/<n>`'s annotated `failed/<id>` tag.
|
||||
pub async fn abort_deploy() -> Result<()> {
|
||||
let _guard = META_LOCK.lock().await;
|
||||
let dir = meta_dir();
|
||||
let dir = crate::paths::meta_root();
|
||||
git(&dir, &["restore", "--staged", "flake.lock"]).await?;
|
||||
git(&dir, &["restore", "flake.lock"]).await
|
||||
}
|
||||
|
|
@ -284,7 +279,7 @@ pub async fn abort_deploy() -> Result<()> {
|
|||
/// semantics — it always wants the latest main.
|
||||
pub async fn lock_update_for_rebuild(name: &str) -> Result<()> {
|
||||
let _guard = META_LOCK.lock().await;
|
||||
let dir = meta_dir();
|
||||
let dir = crate::paths::meta_root();
|
||||
let input = format!("agent-{name}");
|
||||
nix(&dir, &["flake", "update", &input]).await?;
|
||||
if !paths_dirty(&dir, &["flake.lock"]).await? {
|
||||
|
|
@ -325,7 +320,7 @@ fn agent_input_override(applied_dir: &Path, sha: &str) -> String {
|
|||
/// actual apply, so this is the right "would this apply" gate.
|
||||
pub async fn verify_commit(name: &str, applied_dir: &Path, sha: &str) -> Result<()> {
|
||||
let _guard = META_LOCK.lock().await;
|
||||
let dir = meta_dir();
|
||||
let dir = crate::paths::meta_root();
|
||||
let input = format!("agent-{name}");
|
||||
let over = agent_input_override(applied_dir, sha);
|
||||
let attr = format!(".#nixosConfigurations.{name}.config.system.build.toplevel.drvPath");
|
||||
|
|
@ -355,7 +350,7 @@ pub async fn verify_commit(name: &str, applied_dir: &Path, sha: &str) -> Result<
|
|||
/// file) when targeting specific inputs.
|
||||
pub async fn lock_update(inputs: &[String]) -> Result<()> {
|
||||
let _guard = META_LOCK.lock().await;
|
||||
let dir = meta_dir();
|
||||
let dir = crate::paths::meta_root();
|
||||
let mut args: Vec<&str> = vec!["flake", "update"];
|
||||
for i in inputs {
|
||||
args.push(i.as_str());
|
||||
|
|
@ -380,7 +375,7 @@ pub async fn lock_update(inputs: &[String]) -> Result<()> {
|
|||
/// because the per-agent inputs aren't touched.
|
||||
pub async fn lock_update_hyperhive() -> Result<()> {
|
||||
let _guard = META_LOCK.lock().await;
|
||||
let dir = meta_dir();
|
||||
let dir = crate::paths::meta_root();
|
||||
nix(&dir, &["flake", "update", "hyperhive"]).await?;
|
||||
if !paths_dirty(&dir, &["flake.lock"]).await? {
|
||||
return Ok(());
|
||||
|
|
@ -396,7 +391,7 @@ pub async fn lock_update_hyperhive() -> Result<()> {
|
|||
pub async fn commit_tool_groups(agent: &str, groups: &[String]) -> Result<()> {
|
||||
let _guard = META_LOCK.lock().await;
|
||||
crate::tool_groups::set_groups(agent, groups)?;
|
||||
let dir = meta_dir();
|
||||
let dir = crate::paths::meta_root();
|
||||
if crate::tool_groups::tool_groups_path().exists() {
|
||||
git(&dir, &["add", "tool-groups.json"]).await?;
|
||||
}
|
||||
|
|
@ -417,7 +412,7 @@ pub async fn commit_capabilities(agent: &str, caps: &[String]) -> Result<()> {
|
|||
let _guard = META_LOCK.lock().await;
|
||||
crate::capabilities::set_caps(agent, caps)
|
||||
.map_err(|e| anyhow::anyhow!("set capabilities for {agent}: {e}"))?;
|
||||
let dir = meta_dir();
|
||||
let dir = crate::paths::meta_root();
|
||||
if crate::capabilities::capabilities_path().exists() {
|
||||
git(&dir, &["add", "capabilities.json"]).await?;
|
||||
}
|
||||
|
|
@ -450,7 +445,7 @@ pub async fn commit_perms(
|
|||
caps: Option<&[String]>,
|
||||
) -> Result<()> {
|
||||
let _guard = META_LOCK.lock().await;
|
||||
let dir = meta_dir();
|
||||
let dir = crate::paths::meta_root();
|
||||
let mut parts: Vec<&str> = Vec::new();
|
||||
if let Some(groups) = groups {
|
||||
crate::tool_groups::set_groups(agent, groups)?;
|
||||
|
|
@ -492,7 +487,7 @@ pub async fn commit_topology(
|
|||
) -> std::result::Result<(), String> {
|
||||
let _guard = META_LOCK.lock().await;
|
||||
crate::topology::set_parent(child, new_parent)?;
|
||||
let dir = meta_dir();
|
||||
let dir = crate::paths::meta_root();
|
||||
let stage = async {
|
||||
git(&dir, &["add", "topology.json"]).await?;
|
||||
if paths_dirty(&dir, &["topology.json"]).await? {
|
||||
|
|
@ -554,7 +549,7 @@ pub async fn bulk_commit_topology(
|
|||
crate::topology::write(&next).map_err(|e| format!("{e:#}"))?;
|
||||
}
|
||||
// Commit the whole batch as one git operation.
|
||||
let dir = meta_dir();
|
||||
let dir = crate::paths::meta_root();
|
||||
let commit_msg = if moves.len() == 1 {
|
||||
let (child, new_parent) = moves[0];
|
||||
format!("topology: {} → {}", child, new_parent.unwrap_or("<root>"))
|
||||
|
|
|
|||
Loading…
Reference in a new issue