From fc5112aa6a47fcee51dfafc0a60595d1318986bc Mon Sep 17 00:00:00 2001 From: Hermenix Date: Thu, 1 Oct 2026 12:29:35 +0000 Subject: [PATCH] module: let the broker's state be pointed off the system disk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The unit used systemd's StateDirectory=, which can only ever mean /var/lib/ — 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. --- nix/module.nix | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/nix/module.nix b/nix/module.nix index d2857dc..c132f1d 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -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/). 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