diff --git a/nix/modules/hive-c0re.nix b/nix/modules/hive-c0re.nix index b98f9b58..dbe4c3c4 100644 --- a/nix/modules/hive-c0re.nix +++ b/nix/modules/hive-c0re.nix @@ -745,9 +745,30 @@ in User = "root"; PrivateTmp = true; ProtectHome = true; - # hive-priv needs to write to /etc/nixos-containers/ and - # /run/systemd/system/ — "strict" would block both. - ProtectSystem = "false"; + # Harden the file system view: strict makes the entire hierarchy + # read-only by default; ReadWritePaths carves out exactly the + # paths hive-priv must write to at runtime. + # + # Why each entry is needed: + # /etc/nixos-containers — writes .conf (bind mounts, + # network isolation, nspawn flags) + # /run/hive — fallback socket bind if LISTEN_FDS is + # absent (normal path: socket-activated) + # /run/hive-agent — chown/chmod per-agent socket directories + # /run/systemd — container@ unit drop-ins (resource limits) + # + machinectl / systemd-machined state + # /var/lib/nixos-containers — container rootfs written by nixos-container + # /nix — nix store + profile updates during + # container create/update + ProtectSystem = "strict"; + ReadWritePaths = [ + "/etc/nixos-containers" + "/run/hive" + "/run/hive-agent" + "/run/systemd" + "/var/lib/nixos-containers" + "/nix" + ]; # Writable HOME for nix's caches (see environment.HOME above). StateDirectory = "hive-priv"; # nix (run here as root for `nixos-container update --flake