refactor(#2363): single source of truth for DHCP pool size

Move the DHCP pool size constant out of the two separate definitions
(Nix literal + Rust const) into a shared data file: nix/dhcp-pool-size.

- nix/dhcp-pool-size: new file, contains '14'
- hive-gateway.nix: reads via builtins.readFile + toIntBase10
- lifecycle/mod.rs: parses via include_bytes! const block at compile time

Cargo automatically tracks include_bytes! as a file dependency so a
change to nix/dhcp-pool-size triggers recompilation without build.rs.
This commit is contained in:
atlas 2026-07-13 10:56:00 +02:00 committed by mara
commit 3068034463
3 changed files with 24 additions and 6 deletions

View file

@ -92,9 +92,24 @@ pub fn agent_web_port(name: &str) -> u16 {
/// Number of IP addresses at the top of each subnet reserved for the DHCP
/// pool (bridge-attached service containers such as hive-ci). Agents are
/// excluded from this range by the remap in `agent_network_ip`. Must stay
/// in sync with `dhcpPoolSize` in `nix/modules/hive-gateway.nix`.
const DHCP_POOL_SIZE: u32 = 14;
/// excluded from this range by the remap in `agent_network_ip`.
///
/// Single source of truth: `nix/dhcp-pool-size` (one integer, shared with
/// `nix/modules/hive-gateway.nix` which reads the same file via
/// `builtins.readFile`). Parsed at compile time via `include_bytes!`.
const DHCP_POOL_SIZE: u32 = {
let bytes = include_bytes!("../../../nix/dhcp-pool-size");
let mut n: u32 = 0;
let mut i = 0;
while i < bytes.len() {
let b = bytes[i];
if b'0' <= b && b <= b'9' {
n = n * 10 + (b - b'0') as u32;
}
i += 1;
}
n
};
/// Deterministic IPv4 address for an agent inside an isolated subnet.
///