0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-13 13:40:28 +03:00

statsd: restore support for {influx,librato,stackdriver} backends

These packages will be placed into an environment using
`backendsToPackages`. This function explicitly maps backends to
`pkgs.nodePackages.${type}` unless it's a builtin. This ensures that only
valid backends that work on NixOS are used (if not, the build already
breaks at evaluation time).

The log will be redirected to `stdout` to be able to watch the entire
output using `journalctl`.

Configuration parameters for the backends need to be set using
`services.statsd.extraConfig` as each backend has its own options and
all of them shouldn't be validated and checked explicitly and manually.
This commit is contained in:
Maximilian Bosch 2017-11-25 23:54:37 +01:00 committed by Rok Garbas
parent 67a86f7813
commit aaf1e1c4fb
5 changed files with 406 additions and 279 deletions

View file

@ -9,6 +9,12 @@ let
isBuiltinBackend = name:
builtins.elem name [ "graphite" "console" "repeater" ];
backendsToPackages = let
mkMap = list: name:
if isBuiltinBackend name then list
else list ++ [ pkgs.nodePackages.${name} ];
in foldl mkMap [];
configFile = pkgs.writeText "statsd.conf" ''
{
address: "${cfg.listenAddress}",
@ -27,13 +33,21 @@ let
prettyprint: false
},
log: {
backend: "syslog"
backend: "stdout"
},
automaticConfigReload: false${optionalString (cfg.extraConfig != null) ","}
${cfg.extraConfig}
}
'';
deps = pkgs.buildEnv {
name = "statsd-runtime-deps";
pathsToLink = [ "/lib" ];
ignoreCollisions = true;
paths = backendsToPackages cfg.backends;
};
in
{
@ -42,11 +56,7 @@ in
options.services.statsd = {
enable = mkOption {
description = "Whether to enable statsd stats aggregation service";
default = false;
type = types.bool;
};
enable = mkEnableOption "statsd";
listenAddress = mkOption {
description = "Address that statsd listens on over UDP";
@ -110,6 +120,11 @@ in
config = mkIf cfg.enable {
assertions = map (backend: {
assertion = !isBuiltinBackend backend -> hasAttrByPath [ backend ] pkgs.nodePackages;
message = "Only builtin backends (graphite, console, repeater) or backends enumerated in `pkgs.nodePackages` are allowed!";
}) cfg.backends;
users.extraUsers = singleton {
name = "statsd";
uid = config.ids.uids.statsd;
@ -120,9 +135,7 @@ in
description = "Statsd Server";
wantedBy = [ "multi-user.target" ];
environment = {
NODE_PATH=concatMapStringsSep ":"
(pkg: "${builtins.getAttr pkg pkgs.statsd.nodePackages}/lib/node_modules")
(filter (name: !isBuiltinBackend name) cfg.backends);
NODE_PATH = "${deps}/lib/node_modules";
};
serviceConfig = {
ExecStart = "${pkgs.statsd}/bin/statsd ${configFile}";