module: let the broker's state be pointed off the system disk

The unit used systemd's StateDirectory=, which can only ever mean
/var/lib/<name> — on this kind of machine that is the disposable root. The
records the broker adopts and events.jsonl, the audit trail of every accepted
command, are precisely the things that should outlive a reinstall, so they are
now an option (`sessions.stateDir`) and the directory is declared with tmpfiles
so its owner and mode are still declarative.
This commit is contained in:
Hermenix committed 2026-10-01 12:29:35 +00:00
1 parent 30f456c07e
commit fc5112aa6a
1 file changed
+29 -2
+29 -2
View File
@@ -385,6 +385,22 @@ in {
express.
'';
};
stateDir = lib.mkOption {
type = lib.types.str;
default = "/var/lib/hhstream";
description = ''
Where the broker keeps what outlives a broker restart: the live-record
mirrors it adopts on the way back up, tombstones of ended sessions, and
`events.jsonl`, the audit trail of every accepted command.
Point this at durable storage. The default is a system path, which on a
machine whose root is rebuilt from scratch — the usual shape of a
declaratively-managed server — means the audit trail dies with the
next reinstall. On such a machine this belongs on the same disk as the
rest of the state that cannot be rebuilt.
'';
};
};
};
@@ -415,6 +431,18 @@ in {
services.hyprland-headless-stream.package =
lib.mkDefault (pkgs.callPackage ./package.nix {});
# The broker's state directory, when it is not a systemd `StateDirectory=`
# (which cannot be pointed anywhere but /var/lib/<name>). Created here rather
# than by the daemon so its ownership is declarative and it survives a
# restart of the unit with the right mode.
systemd.tmpfiles.settings = lib.mkIf cfg.sessions.enable {
"10-hhstream-sessions".${cfg.sessions.stateDir}.d = {
user = cfg.sessions.user;
group = cfg.sessions.group;
mode = "0700";
};
};
users.users.${cfg.user} = {
isSystemUser = true;
group = cfg.group;
@@ -547,7 +575,6 @@ in {
RuntimeDirectory = "hhstream";
RuntimeDirectoryMode = "0750";
StateDirectory = "hhstream";
WorkingDirectory = "/run/hhstream";
UMask = "0007";
@@ -574,7 +601,7 @@ in {
"--runtime-dir"
"/run/hhstream"
"--state-dir"
"/var/lib/hhstream"
cfg.sessions.stateDir
"--config"
(toString (
if cfg.sessions.configFile != null then cfg.sessions.configFile else sessionsConfig