refactor(#2754): make the container weights Option, not a 0 sentinel

Encoding "not configured" as weight 0 worked (the writer omitted the
line) but the type lied: 0 is not a legal cgroup v2 weight, and every
reader had to know the sentinel. Use Option<u32> end to end instead —
wire type, priv_client, HiveEnv, drop-in writer — so "unset" is a state
of the type rather than a magic value.

The nix options become nullOr, keeping their default of 80; null now
expresses "leave the setting out of the drop-in entirely" declaratively,
which is the useful shape on a host whose IO scheduler ignores
io.weight anyway.

Backward compat is unchanged: the fields stay #[serde(default)], so a
request from an older hive-c0re deserialises to None and reproduces the
pre-weights drop-in byte for byte. The test that pins that now passes
None instead of 0.
This commit is contained in:
atlas 2026-07-27 10:55:29 +02:00
commit 5d3f2af75e
7 changed files with 59 additions and 51 deletions

View file

@ -302,9 +302,9 @@
};
agentCpuWeight = lib.mkOption {
type = lib.types.ints.between 1 10000;
type = lib.types.nullOr (lib.types.ints.between 1 10000);
default = 80;
example = 50;
example = null;
description = ''
systemd `CPUWeight=` applied to every agent container via the
same drop-in as `agentCpuQuota`. This is the cgroup v2
@ -321,13 +321,17 @@
`hive-matrix`), which stay at `100`. Note this is a hive-wide
value, so it does not rank agents against *each other*: they all
share one weight.
Set to `null` to leave `CPUWeight=` out of the drop-in entirely
the container then inherits the kernel default and the generated
unit file is identical to one from before this option existed.
'';
};
agentIoWeight = lib.mkOption {
type = lib.types.ints.between 1 10000;
type = lib.types.nullOr (lib.types.ints.between 1 10000);
default = 80;
example = 50;
example = null;
description = ''
systemd `IOWeight=` applied to every agent container via the
same drop-in as `agentCpuQuota` the block-IO counterpart of
@ -340,7 +344,8 @@
scheduler. On a host running `none`/`mq-deadline`/`kyber` without
iocost QoS configured, systemd writes the value and the kernel
ignores it harmless, but it will measure as a no-op. Check with
`cat /sys/fs/cgroup/io.cost.qos` on the host.
`cat /sys/fs/cgroup/io.cost.qos` on the host, and set this to
`null` to omit the setting rather than write one nothing reads.
'';
};