nixos/stubby: Support fine-grained logLevel

In much older versions, Stubby only supported debug logging, but that is
no longer true, so support the fine-grained log level.
This commit is contained in:
Andrew Marshall 2022-08-06 12:05:24 -04:00 committed by Emery Hemingway
parent 194fd9b484
commit 87245df5d3

View file

@ -7,7 +7,9 @@ let
settingsFormat = pkgs.formats.yaml { };
confFile = settingsFormat.generate "stubby.yml" cfg.settings;
in {
imports = map (x:
imports = [
(mkRemovedOptionModule [ "stubby" "debugLogging" ] "Use services.stubby.logLevel = \"debug\"; instead.")
] ++ map (x:
(mkRemovedOptionModule [ "services" "stubby" x ]
"Stubby configuration moved to services.stubby.settings.")) [
"authenticationMode"
@ -49,10 +51,22 @@ in {
'';
};
debugLogging = mkOption {
default = false;
type = types.bool;
description = lib.mdDoc "Enable or disable debug level logging.";
logLevel = let
logLevels = {
emerg = 0;
alert = 1;
crit = 2;
error = 3;
warning = 4;
notice = 5;
info = 6;
debug = 7;
};
in mkOption {
default = null;
type = types.nullOr (types.enum (attrNames logLevels ++ attrValues logLevels));
apply = v: if isString v then logLevels.${v} else v;
description = lib.mdDoc "Log verbosity (syslog keyword or level).";
};
};
@ -80,7 +94,7 @@ in {
Type = "notify";
AmbientCapabilities = "CAP_NET_BIND_SERVICE";
CapabilityBoundingSet = "CAP_NET_BIND_SERVICE";
ExecStart = "${pkgs.stubby}/bin/stubby -C ${confFile} ${optionalString cfg.debugLogging "-l"}";
ExecStart = "${pkgs.stubby}/bin/stubby -C ${confFile} ${optionalString (cfg.logLevel != null) "-v ${toString cfg.logLevel}"}";
DynamicUser = true;
CacheDirectory = "stubby";
};