nixos/victorialogs: add basicAuth options

Shawn8901 29a7ca73 656a427a

Changed files
+39 -4
nixos
modules
services
databases
+39 -4
nixos/modules/services/databases/victorialogs.nix
···
config,
pkgs,
lib,
+
utils,
...
}:
let
···
"-storageDataPath=/var/lib/${cfg.stateDir}"
"-httpListenAddr=${cfg.listenAddress}"
]
-
++ cfg.extraOptions;
+
++ lib.optionals (cfg.basicAuthUsername != null) [
+
"-httpAuth.username=${cfg.basicAuthUsername}"
+
]
+
++ lib.optionals (cfg.basicAuthPasswordFile != null) [
+
"-httpAuth.password=file://%d/basic_auth_password"
+
];
in
{
options.services.victorialogs = {
···
This directory will be created automatically using systemd's StateDirectory mechanism.
'';
};
+
basicAuthUsername = lib.mkOption {
+
default = null;
+
type = lib.types.nullOr lib.types.str;
+
description = ''
+
Basic Auth username used to protect VictoriaLogs 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 VictoriaLogs instance by authorization
+
'';
+
};
extraOptions = mkOption {
type = types.listOf types.str;
default = [ ];
example = literalExpression ''
[
-
"-httpAuth.username=username"
-
"-httpAuth.password=file:///abs/path/to/file"
"-loggerLevel=WARN"
]
'';
···
};
};
config = mkIf cfg.enable {
+
+
assertions = [
+
{
+
assertion =
+
(cfg.basicAuthUsername == null && cfg.basicAuthPasswordFile == null)
+
|| (cfg.basicAuthUsername != null && cfg.basicAuthPasswordFile != null);
+
message = "Both basicAuthUsername and basicAuthPasswordFile must be set together to enable basicAuth functionality, or neither should be set.";
+
}
+
];
+
systemd.services.victorialogs = {
description = "VictoriaLogs logs database";
wantedBy = [ "multi-user.target" ];
···
startLimitBurst = 5;
serviceConfig = {
-
ExecStart = escapeShellArgs startCLIList;
+
ExecStart = lib.concatStringsSep " " [
+
(escapeShellArgs startCLIList)
+
(utils.escapeSystemdExecArgs cfg.extraOptions)
+
];
DynamicUser = true;
+
LoadCredential = lib.optional (
+
cfg.basicAuthPasswordFile != null
+
) "basic_auth_password:${cfg.basicAuthPasswordFile}";
RestartSec = 1;
Restart = "on-failure";
RuntimeDirectory = "victorialogs";