diff --git a/hive-c0re/src/lifecycle.rs b/hive-c0re/src/lifecycle.rs index 005bb7e..2b9656d 100644 --- a/hive-c0re/src/lifecycle.rs +++ b/hive-c0re/src/lifecycle.rs @@ -31,6 +31,11 @@ pub const CONTAINER_CLAUDE_MOUNT: &str = "/root/.claude"; /// state here; persists across destroy/recreate. pub const CONTAINER_NOTES_MOUNT: &str = "/state"; +/// Mount point of the shared directory accessible to all agents. +/// All agents can read/write here; agents should only put things they're +/// willing to lose (other agents may delete them). +pub const CONTAINER_SHARED_MOUNT: &str = "/shared"; + const GIT_NAME: &str = "c0re"; const GIT_EMAIL: &str = "c0re@hyperhive"; @@ -722,19 +727,27 @@ const HOST_APPLIED_ROOT: &str = "/var/lib/hyperhive/applied"; /// `meta::meta_dir()` but duplicated here so lifecycle stays a leaf. const HOST_META_ROOT: &str = "/var/lib/hyperhive/meta"; +/// Shared directory accessible to all agents. All agents bind-mount this RW. +const HOST_SHARED_ROOT: &str = "/var/lib/hyperhive/shared"; + fn set_nspawn_flags( container: &str, runtime_dir: &Path, claude_dir: &Path, notes_dir: &Path, ) -> Result<()> { + // Ensure /shared directory exists before binding. systemd-nspawn requires the bind source to exist. + std::fs::create_dir_all(HOST_SHARED_ROOT) + .with_context(|| format!("create {HOST_SHARED_ROOT}"))?; + let path = format!("/etc/nixos-containers/{container}.conf"); let original = std::fs::read_to_string(&path).with_context(|| format!("read {path}"))?; let mut binds = format!( - "--bind={runtime}:{CONTAINER_RUNTIME_MOUNT} --bind={claude}:{CONTAINER_CLAUDE_MOUNT} --bind={notes}:{CONTAINER_NOTES_MOUNT}", + "--bind={runtime}:{CONTAINER_RUNTIME_MOUNT} --bind={claude}:{CONTAINER_CLAUDE_MOUNT} --bind={notes}:{CONTAINER_NOTES_MOUNT} --bind={shared}:{CONTAINER_SHARED_MOUNT}", runtime = runtime_dir.display(), claude = claude_dir.display(), notes = notes_dir.display(), + shared = HOST_SHARED_ROOT, ); if container == MANAGER_NAME { use std::fmt::Write as _;