feat(#2170): split docs/ into its own meta-flake input

This commit is contained in:
damocles 2026-07-04 11:26:13 +02:00
commit b5acd60cf5
5 changed files with 148 additions and 18 deletions

View file

@ -59,6 +59,11 @@ pub struct Coordinator {
/// URL of the hyperhive flake (no fragment). Inlined into per-agent
/// `flake.nix` files as `inputs.hyperhive.url`.
pub hyperhive_flake: String,
/// URL of the narrow `docs/` source (no fragment). Inlined into the
/// meta `flake.nix` as `inputs.hyperhive-docs.url` and threaded to
/// each agent as `hyperhive.docs.source`. Its own store path
/// so doc edits don't re-hash `hyperhive_flake`.
pub hyperhive_docs_flake: String,
/// Store-path URL of the nixpkgs to wire into the meta flake as
/// `inputs.nixpkgs.url`. Populated by `--nixpkgs-flake` (set by the
/// NixOS module to `"path:${pkgs.path}"` so the meta flake always
@ -197,6 +202,11 @@ pub struct Coordinator {
#[serde(default)]
pub struct HiveEnv {
pub hyperhive_flake: String,
/// Store-path URL of the narrow `docs/` source, wired into the meta
/// flake as `inputs.hyperhive-docs.url` and threaded to each agent as
/// `hyperhive.docs.source`. Separate from `hyperhive_flake`
/// so a doc edit only re-locks this input, not the whole source.
pub hyperhive_docs_flake: String,
pub nixpkgs_flake: String,
pub dashboard_port: u16,
pub operator_pronouns: String,
@ -211,6 +221,7 @@ impl Default for HiveEnv {
fn default() -> Self {
Self {
hyperhive_flake: "/etc/hyperhive".to_string(),
hyperhive_docs_flake: String::new(),
nixpkgs_flake: String::new(),
dashboard_port: 7000,
operator_pronouns: "she/her".to_string(),
@ -425,6 +436,7 @@ impl Coordinator {
) -> Result<Self> {
let HiveEnv {
hyperhive_flake,
hyperhive_docs_flake,
nixpkgs_flake,
dashboard_port,
operator_pronouns,
@ -467,6 +479,7 @@ impl Coordinator {
build_logs,
audit_log,
hyperhive_flake,
hyperhive_docs_flake,
nixpkgs_flake,
dashboard_port,
operator_pronouns,
@ -496,6 +509,7 @@ impl Coordinator {
pub fn hive_env(&self) -> HiveEnv {
HiveEnv {
hyperhive_flake: self.hyperhive_flake.clone(),
hyperhive_docs_flake: self.hyperhive_docs_flake.clone(),
nixpkgs_flake: self.nixpkgs_flake.clone(),
dashboard_port: self.dashboard_port,
operator_pronouns: self.operator_pronouns.clone(),

View file

@ -56,6 +56,7 @@ pub async fn sync_agents(hive: &HiveEnv, agents: &[AgentSpec]) -> Result<()> {
let new_flake = render_flake(
&hive.hyperhive_flake,
&hive.hyperhive_docs_flake,
&hive.nixpkgs_flake,
hive.dashboard_port,
&hive.operator_pronouns,
@ -561,6 +562,7 @@ pub async fn bulk_commit_topology(
fn render_flake(
hyperhive_flake: &str,
docs_flake: &str,
nixpkgs_flake: &str,
dashboard_port: u16,
operator_pronouns: &str,
@ -569,6 +571,7 @@ fn render_flake(
) -> String {
render_flake_with_lookup(
hyperhive_flake,
docs_flake,
nixpkgs_flake,
dashboard_port,
operator_pronouns,
@ -844,6 +847,7 @@ fn agent_canonical_inputs(name: &str) -> Vec<&'static str> {
)]
fn render_flake_with_lookup<F>(
hyperhive_flake: &str,
docs_flake: &str,
nixpkgs_flake: &str,
dashboard_port: u16,
operator_pronouns: &str,
@ -882,6 +886,17 @@ where
let _ = writeln!(out, " hyperhive.url = \"{hyperhive_flake}\";");
out.push_str(" hyperhive.inputs.nixpkgs.follows = \"nixpkgs\";\n");
}
// Narrow `docs/` source as its own input so a doc edit only
// re-locks THIS input instead of re-hashing the whole `hyperhive`
// source. Threaded to each agent below as `hyperhive.docs.source`.
// Empty = hive-c0re not built with the option wired up (legacy);
// agents then keep the harness-base default (`pkgs.hyperhive-docs`).
if !docs_flake.is_empty() {
// `flake = false`: the docs/ tree is a plain source (no flake.nix),
// so nix must treat it as raw source, not evaluate it as a flake.
let _ = writeln!(out, " hyperhive-docs.url = \"{docs_flake}\";");
out.push_str(" hyperhive-docs.flake = false;\n");
}
for spec in agents {
let _ = writeln!(
out,
@ -930,6 +945,14 @@ where
{
"#,
);
// Point the in-container docs dir (`$HIVE_DOCS_DIR`) at the narrow
// `hyperhive-docs` input instead of the harness-base default
// (`pkgs.hyperhive-docs`, built from the now-docs-stripped source).
// `inputs."hyperhive-docs"` is reachable via the outputs `@inputs`
// capture. Emitted only when the input exists (docs_flake non-empty).
if !docs_flake.is_empty() {
out.push_str(" hyperhive.docs.source = inputs.\"hyperhive-docs\".outPath;\n");
}
// CA trust: embed every hive-trusted CA so each agent validates them at
// build time. The list is the hive's own self-signed CA (when active)
// plus every peer-hive root CA (`swarm.peers.<d>.caCert`) — a peer CA is
@ -1274,6 +1297,7 @@ mod tests {
fn render_flake_uses_explicit_nixpkgs_url_when_provided() {
let out = render_flake(
"github:example/hyperhive",
"path:/nix/store/bbbb-hyperhive-docs-source",
"path:/nix/store/aaaa-nixpkgs-source",
8000,
"she/her",
@ -1294,6 +1318,39 @@ mod tests {
!out.contains("nixpkgs.follows = \"hyperhive"),
"old-style follows must not appear when flake args are set:\n{out}"
);
// the narrow docs source is its own non-flake input, and each
// agent's docs dir resolves from it rather than pkgs.hyperhive-docs.
assert!(
out.contains("hyperhive-docs.url = \"path:/nix/store/bbbb-hyperhive-docs-source\""),
"expected hyperhive-docs input url:\n{out}"
);
assert!(
out.contains("hyperhive-docs.flake = false;"),
"docs source is not a flake, must be flake = false:\n{out}"
);
assert!(
out.contains("hyperhive.docs.source = inputs.\"hyperhive-docs\".outPath;"),
"expected per-agent docs source wired to the input:\n{out}"
);
}
#[test]
fn render_flake_omits_docs_input_when_docs_flake_empty() {
// Legacy / not-wired-up: empty docs_flake emits no docs input and
// leaves each agent on the harness-base default (pkgs.hyperhive-docs).
let out = render_flake(
"github:example/hyperhive",
"",
"path:/nix/store/aaaa-nixpkgs-source",
8000,
"she/her",
&std::collections::HashMap::new(),
&[sample_spec("alice", false, 9001)],
);
assert!(
!out.contains("hyperhive-docs"),
"no docs input/source when docs_flake is empty:\n{out}"
);
}
#[test]
@ -1302,6 +1359,7 @@ mod tests {
// for any code path that can't inject pkgs.path).
let out = render_flake(
"github:example/hyperhive",
"path:/nix/store/bbbb-hyperhive-docs-source",
"",
8000,
"she/her",
@ -1330,6 +1388,7 @@ mod tests {
};
let out = render_flake_with_lookup(
"github:example/hyperhive",
"path:/nix/store/bbbb-hyperhive-docs-source",
"path:/nix/store/aaaa-nixpkgs-source",
8000,
"she/her",
@ -1361,6 +1420,7 @@ mod tests {
fn render_flake_skips_canonical_follows_when_lookup_returns_empty() {
let out = render_flake_with_lookup(
"github:example/hyperhive",
"path:/nix/store/bbbb-hyperhive-docs-source",
"path:/nix/store/aaaa-nixpkgs-source",
8000,
"she/her",
@ -1394,6 +1454,7 @@ mod tests {
}
let out = render_flake(
"github:example/hyperhive",
"path:/nix/store/bbbb-hyperhive-docs-source",
"path:/nix/store/aaaa-nixpkgs-source",
8000,
"she/her",
@ -1441,6 +1502,7 @@ mod tests {
let render = || {
render_flake(
"github:example/hyperhive",
"path:/nix/store/bbbb-hyperhive-docs-source",
"path:/nix/store/aaaa-nixpkgs-source",
8000,
"she/her",
@ -1522,6 +1584,7 @@ mod tests {
let render = || {
render_flake(
"github:example/hyperhive",
"path:/nix/store/bbbb-hyperhive-docs-source",
"path:/nix/store/aaaa-nixpkgs-source",
8000,
"she/her",