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.
wip/yesman
Shea Levy 12 years ago
parent 8712e1dafc
commit a2b59f595f
  1. 29
      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
}
''}";
};
};
})];
}

Loading…
Cancel
Save