fix: add writable state directory for flake collector

When running nix flake metadata, nix and git need writable cache
directories. System service users have home set to /var/empty which
is read-only, causing "cannot create directories" errors.

Add StateDirectory and set HOME/XDG_CACHE_HOME environment variables
to /var/lib/nixos-exporter when flake collector is enabled.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-06 23:27:07 +01:00
parent a065eab759
commit 95bf85dce4

View File

@@ -120,6 +120,13 @@ in
RestrictSUIDSGID = true;
MemoryDenyWriteExecute = true;
LockPersonality = true;
} // lib.optionalAttrs cfg.flake.enable {
# nix and git need writable cache directories
StateDirectory = "nixos-exporter";
Environment = [
"HOME=/var/lib/nixos-exporter"
"XDG_CACHE_HOME=/var/lib/nixos-exporter/.cache"
];
};
};