Skip to content

Commit

Permalink
nixos/victoriametrics: Add ability to pass basicAuthPasswordFile
Browse files Browse the repository at this point in the history
  • Loading branch information
Sudokamikaze committed Jan 4, 2025
1 parent cb8c948 commit 1b51a68
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions nixos/modules/services/databases/victoriametrics.nix
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ in
'';
};

basicAuthUsername = lib.mkOption {
default = null;
type = lib.types.nullOr lib.types.str;
description = ''
Basic Auth username used to protect VictoriaMetrics instance by authorization
'';
};

basicAuthPasswordFile = lib.mkOption {
default = null;
type = lib.types.nullOr lib.types.str;
description = ''
File that contains the Basic Auth password used to protect VictoriaMetrics instance by authorization
'';
};

prometheusConfig = lib.mkOption {
type = lib.types.submodule { freeformType = settingsFormat.type; };
default = { };
Expand Down Expand Up @@ -116,8 +132,6 @@ in
default = [ ];
example = literalExpression ''
[
"-httpAuth.username=username"
"-httpAuth.password=file:///abs/path/to/file"
"-loggerLevel=WARN"
]
'';
Expand All @@ -140,9 +154,15 @@ in
ExecStart = lib.escapeShellArgs (
startCLIList
++ lib.optionals (cfg.prometheusConfig != { }) [ "-promscrape.config=${prometheusConfigYml}" ]
++ lib.optional (cfg.basicAuthUsername != null) "-httpAuth.username=${cfg.basicAuthUsername}"
++ lib.optional (cfg.basicAuthPasswordFile != null) "-httpAuth.password=file://\${CREDENTIALS_DIRECTORY}/basic_auth_password"
);

DynamicUser = true;
LoadCredential = lib.optional (cfg.basicAuthPasswordFile != null) [
"basic_auth_password:${cfg.basicAuthPasswordFile}"
];

RestartSec = 1;
Restart = "on-failure";
RuntimeDirectory = "victoriametrics";
Expand Down

0 comments on commit 1b51a68

Please sign in to comment.