diff --git a/modules/services/logging/logstash.nix b/modules/services/logging/logstash.nix index 9387a731db9..32e2f17d189 100644 --- a/modules/services/logging/logstash.nix +++ b/modules/services/logging/logstash.nix @@ -86,18 +86,17 @@ in inputConfig = mkOption { default = {}; description = '' - An attr set representing a logstash configuration's input section. + A nixexpr representing a logstash configuration's input section. logstash configs are name-value pairs, where values can be bools, strings, numbers, arrays, hashes, or other name-value pairs, and names are strings that can be repeated. name-value pairs with no - repeats are represented by attr sets. name-value pairs with repeats - are represented by an attrset with attr "__type" = "repeated" and - attr "values" as a list of {name; value;} attrsets. - bools, strings, ints, and arrays are mapped directly. Floats are - represented as an attrset with attr "__type" = "float" and attr value - set to the string representation of the float. Hashes are represented - with attr "__type" = "hash" and attr value set to an attr set - corresponding to the hash. + repeats are represented by attr sets. bools, strings, ints, and + arrays are mapped directly. name-value pairs with repeats can be + generated by the config.lib.logstash.mkNameValuePairs function, which + takes a list of attrsets and combines them while preserving attribute + name duplicates if they occur. Similarly, there are the mkFloat and + mkHash functions, which take a string representation of a float and an + attrset, respectively. ''; merge = mergeConfigs; }; @@ -125,7 +124,15 @@ in ###### implementation - config = mkIf cfg.enable { + config = mkMerge [ { + lib.logstash = { + mkFloat = stringRep: { __type = "float"; value = stringRep; }; + + mkHash = attrs: { __type = "hash"; value = attrs; }; + + mkNameValuePairs = mergeConfigs; + }; + } ( mkIf cfg.enable { # Always log to stdout services.logstash.outputConfig = { stdout = {}; }; @@ -148,5 +155,5 @@ in } ''}"; }; - }; + })]; }