refactor(#2285): inline remaining 1:1 path wrappers (meta_dir, marker fns, host_conf_path)

This commit is contained in:
damocles 2026-07-10 20:30:01 +02:00 committed by mara
commit 556a213320
11 changed files with 39 additions and 72 deletions

View file

@ -4,7 +4,7 @@
//! Kill-switch: `HIVE_SKIP_META_MIGRATION=1`. Full migration sequence
//! and phase details: `docs/approvals.md::Migration from the pre-tag`.
use std::path::{Path, PathBuf};
use std::path::Path;
use std::sync::Arc;
use anyhow::{Context, Result};
@ -17,18 +17,6 @@ use crate::tool_groups;
const KILL_SWITCH: &str = "HIVE_SKIP_META_MIGRATION";
/// Marker for phase 4. Once present, container repoint is skipped on
/// future restarts.
fn repoint_marker() -> PathBuf {
crate::paths::meta_migration_marker()
}
/// Marker for phase 5. Once present, root→h-root container rename is
/// skipped on future restarts.
fn hroot_rename_marker() -> PathBuf {
crate::paths::hroot_rename_marker()
}
/// Substring that identifies the *current* agent flake boilerplate.
/// Bumped whenever the template changes so the startup migration
/// re-renders existing agents onto the new shape. Today the marker
@ -83,7 +71,7 @@ pub async fn run(coord: &Arc<Coordinator>) -> Result<()> {
}
// Phase 4: container repoint, guarded by marker.
if repoint_marker().exists() {
if crate::paths::meta_migration_marker().exists() {
tracing::debug!("migration: phase 4 marker present, skipping repoint");
return Ok(());
}
@ -104,7 +92,7 @@ pub async fn run(coord: &Arc<Coordinator>) -> Result<()> {
}
if all_ok
&& !names.is_empty()
&& let Err(e) = std::fs::write(repoint_marker(), b"done\n")
&& let Err(e) = std::fs::write(crate::paths::meta_migration_marker(), b"done\n")
{
tracing::warn!(error = ?e, "migration: write repoint marker failed");
}
@ -169,20 +157,20 @@ fn migrate_harness_files(name: &str) {
/// conf files present; on the next hive-c0re start the marker is
/// absent so the phase retries.
async fn rename_manager_container(coord: &Arc<Coordinator>) {
if hroot_rename_marker().exists() {
if crate::paths::hroot_rename_marker().exists() {
return;
}
let old_conf = std::path::PathBuf::from("/etc/nixos-containers/root.conf");
let new_conf = std::path::PathBuf::from("/etc/nixos-containers/h-root.conf");
if !old_conf.exists() {
// Fresh install — root container was never created under the old name.
let _ = std::fs::write(hroot_rename_marker(), b"done\n");
let _ = std::fs::write(crate::paths::hroot_rename_marker(), b"done\n");
return;
}
if new_conf.exists() {
// Already renamed (but marker was lost — write it and return).
tracing::info!("migration phase 5: h-root.conf already present, marking done");
let _ = std::fs::write(hroot_rename_marker(), b"done\n");
let _ = std::fs::write(crate::paths::hroot_rename_marker(), b"done\n");
return;
}
tracing::info!("migration phase 5: renaming root container to h-root");
@ -243,7 +231,7 @@ async fn rename_manager_container(coord: &Arc<Coordinator>) {
}
tracing::info!("migration phase 5: root container renamed to h-root");
let _ = std::fs::write(hroot_rename_marker(), b"done\n");
let _ = std::fs::write(crate::paths::hroot_rename_marker(), b"done\n");
// Clean up the old conf file so `nixos-container list` doesn't show
// a stale stopped `root` entry. Best-effort; a failure here is
// harmless — h-root is already running and the marker is written.
@ -312,7 +300,7 @@ async fn migrate_applied_repo(name: &str) -> Result<()> {
async fn repoint_container(name: &str) -> Result<()> {
let container = lifecycle::container_name(name);
let flake_ref = format!("{}#{name}", meta::meta_dir().display());
let flake_ref = format!("{}#{name}", crate::paths::meta_root().display());
let out = Command::new("nixos-container")
.args(["update", &container, "--flake", &flake_ref])
.output()