logstash: Export config.lib.logstash.mk{Float,Hash,NameValuePairs}.

This allows hiding the implementation details for how to represent logstash
config types that don't directly map to nix expressions, particularly floats,
hashes, and name-value pair sets with repeated names. Instead of setting
__type and value directly, the user now uses these convenience functions to
generate their logstash config.
This commit is contained in:
Shea Levy 2012-07-12 14:15:43 -04:00
parent 8712e1dafc
commit a2b59f595f
1 changed files with 18 additions and 11 deletions

View File

@ -86,18 +86,17 @@ in
inputConfig = mkOption { inputConfig = mkOption {
default = {}; default = {};
description = '' 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, logstash configs are name-value pairs, where values can be bools,
strings, numbers, arrays, hashes, or other name-value pairs, strings, numbers, arrays, hashes, or other name-value pairs,
and names are strings that can be repeated. name-value pairs with no and names are strings that can be repeated. name-value pairs with no
repeats are represented by attr sets. name-value pairs with repeats repeats are represented by attr sets. bools, strings, ints, and
are represented by an attrset with attr "__type" = "repeated" and arrays are mapped directly. name-value pairs with repeats can be
attr "values" as a list of {name; value;} attrsets. generated by the config.lib.logstash.mkNameValuePairs function, which
bools, strings, ints, and arrays are mapped directly. Floats are takes a list of attrsets and combines them while preserving attribute
represented as an attrset with attr "__type" = "float" and attr value name duplicates if they occur. Similarly, there are the mkFloat and
set to the string representation of the float. Hashes are represented mkHash functions, which take a string representation of a float and an
with attr "__type" = "hash" and attr value set to an attr set attrset, respectively.
corresponding to the hash.
''; '';
merge = mergeConfigs; merge = mergeConfigs;
}; };
@ -125,7 +124,15 @@ in
###### implementation ###### 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 # Always log to stdout
services.logstash.outputConfig = { stdout = {}; }; services.logstash.outputConfig = { stdout = {}; };
@ -148,5 +155,5 @@ in
} }
''}"; ''}";
}; };
}; })];
} }