1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-12-04 11:32:03 +00:00

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

View file

@ -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
}
''}";
};
};
})];
}