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