hive-c0re: nixos-container lifecycle (spawn/kill/rebuild/list)

This commit is contained in:
müde 2026-05-14 20:51:35 +02:00
parent 0ec54ecf89
commit 90798b936e
3 changed files with 88 additions and 15 deletions

View file

@ -5,6 +5,8 @@ use hive_sh4re::{HostRequest, HostResponse};
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
use tokio::net::{UnixListener, UnixStream};
use crate::lifecycle;
pub async fn serve(socket: &Path, agent_flake: &str) -> Result<()> {
if let Some(parent) = socket.parent() {
std::fs::create_dir_all(parent)
@ -51,20 +53,30 @@ async fn handle(stream: UnixStream, agent_flake: &str) -> Result<()> {
}
}
async fn dispatch(req: &HostRequest, _agent_flake: &str) -> HostResponse {
match req {
HostRequest::Spawn { name } => {
tracing::info!(%name, "spawn (stub)");
HostResponse::error("spawn: nixos-container integration pending")
}
HostRequest::Kill { name } => {
tracing::info!(%name, "kill (stub)");
HostResponse::error("kill: nixos-container integration pending")
}
HostRequest::Rebuild { name } => {
tracing::info!(%name, "rebuild (stub)");
HostResponse::error("rebuild: nixos-container integration pending")
}
HostRequest::List => HostResponse::list(Vec::new()),
async fn dispatch(req: &HostRequest, agent_flake: &str) -> HostResponse {
let result: anyhow::Result<HostResponse> = async {
Ok(match req {
HostRequest::Spawn { name } => {
tracing::info!(%name, "spawn");
lifecycle::spawn(name, agent_flake).await?;
HostResponse::success()
}
HostRequest::Kill { name } => {
tracing::info!(%name, "kill");
lifecycle::kill(name).await?;
HostResponse::success()
}
HostRequest::Rebuild { name } => {
tracing::info!(%name, "rebuild");
lifecycle::rebuild(name, agent_flake).await?;
HostResponse::success()
}
HostRequest::List => HostResponse::list(lifecycle::list().await?),
})
}
.await;
match result {
Ok(r) => r,
Err(e) => HostResponse::error(format!("{e:#}")),
}
}