Skip to content

Commit

Permalink
nixos/promtail: configFile for passing path as config (#322426)
Browse files Browse the repository at this point in the history
  • Loading branch information
NetaliDev authored Nov 8, 2024
2 parents e69ff6f + 518bc9c commit 8db8859
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions nixos/modules/services/logging/promtail.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,29 @@ let

allowPositionsFile = !lib.hasPrefix "/var/cache/promtail" positionsFile;
positionsFile = cfg.configuration.positions.filename;

configFile = if cfg.configFile != null
then cfg.configFile
else prettyJSON cfg.configuration;

in {
options.services.promtail = with types; {
enable = mkEnableOption "the Promtail ingresser";


configuration = mkOption {
type = (pkgs.formats.json {}).type;
description = ''
Specify the configuration for Promtail in Nix.
This option will be ignored if `services.promtail.configFile` is defined.
'';
};

configFile = mkOption {
type = nullOr path;
default = null;
description = ''
Config file path for Promtail.
If this option is defined, the value of `services.promtail.configuration` will be ignored.
'';
};

Expand All @@ -42,14 +56,14 @@ in {
stopIfChanged = false;

preStart = ''
${lib.getExe pkgs.promtail} -config.file=${prettyJSON cfg.configuration} -check-syntax
${lib.getExe pkgs.promtail} -config.file=${configFile} -check-syntax
'';

serviceConfig = {
Restart = "on-failure";
TimeoutStopSec = 10;

ExecStart = "${pkgs.promtail}/bin/promtail -config.file=${prettyJSON cfg.configuration} ${escapeShellArgs cfg.extraFlags}";
ExecStart = "${pkgs.promtail}/bin/promtail -config.file=${configFile} ${escapeShellArgs cfg.extraFlags}";

ProtectSystem = "strict";
ProtectHome = true;
Expand Down

0 comments on commit 8db8859

Please sign in to comment.