nixos/promtail: Allow write access to positions file if not in CacheDirectory

Because of `ProtectSystem=strict`, Promtail cannot write to the positions
file if it's not in its `CacheDirectory` (the default value).
This commit is contained in:
Zhaofeng Li 2021-08-25 22:17:17 -07:00
parent ce38fecabe
commit b6ad701a2c

View File

@ -7,6 +7,9 @@ let
'';
allowSystemdJournal = cfg.configuration ? scrape_configs && lib.any (v: v ? journal) cfg.configuration.scrape_configs;
allowPositionsFile = !lib.hasPrefix "/var/cache/promtail" positionsFile;
positionsFile = cfg.configuration.positions.filename;
in {
options.services.promtail = with types; {
enable = mkEnableOption "the Promtail ingresser";
@ -53,6 +56,7 @@ in {
RestrictSUIDSGID = true;
PrivateMounts = true;
CacheDirectory = "promtail";
ReadWritePaths = lib.optional allowPositionsFile (builtins.dirOf positionsFile);
User = "promtail";
Group = "promtail";