2014-08-25 13:40:40 +01:00
|
|
|
{ config, pkgs, lib, ... }:
|
2014-08-23 16:04:34 +01:00
|
|
|
|
|
|
|
with pkgs;
|
2014-08-25 13:40:40 +01:00
|
|
|
with lib;
|
2014-08-23 16:04:34 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.riemann;
|
|
|
|
|
|
|
|
classpath = concatStringsSep ":" (
|
|
|
|
cfg.extraClasspathEntries ++ [ "${riemann}/share/java/riemann.jar" ]
|
|
|
|
);
|
|
|
|
|
2014-11-19 11:55:42 +00:00
|
|
|
riemannConfig = concatStringsSep "\n" (
|
|
|
|
[cfg.config] ++ (map (f: ''(load-file "${f}")'') cfg.configFiles)
|
|
|
|
);
|
|
|
|
|
2014-08-23 16:04:34 +01:00
|
|
|
launcher = writeScriptBin "riemann" ''
|
|
|
|
#!/bin/sh
|
2018-08-01 13:36:16 +01:00
|
|
|
exec ${jdk}/bin/java ${concatStringsSep " " cfg.extraJavaOpts} \
|
2014-08-23 16:04:34 +01:00
|
|
|
-cp ${classpath} \
|
2018-08-01 13:36:16 +01:00
|
|
|
riemann.bin ${cfg.configFile}
|
2014-08-23 16:04:34 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.riemann = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable the Riemann network monitoring daemon.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
config = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
description = ''
|
2018-08-01 13:36:16 +01:00
|
|
|
Contents of the Riemann configuration file. For more complicated
|
|
|
|
config you should use configFile.
|
2014-08-23 16:04:34 +01:00
|
|
|
'';
|
|
|
|
};
|
2014-11-19 11:55:42 +00:00
|
|
|
configFiles = mkOption {
|
|
|
|
type = with types; listOf path;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
Extra files containing Riemann configuration. These files will be
|
|
|
|
loaded at runtime by Riemann (with Clojure's
|
|
|
|
<literal>load-file</literal> function) at the end of the
|
2018-08-01 13:36:16 +01:00
|
|
|
configuration if you use the config option, this is ignored if you
|
|
|
|
use configFile.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
configFile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
A Riemann config file. Any files in the same directory as this file
|
|
|
|
will be added to the classpath by Riemann.
|
2014-11-19 11:55:42 +00:00
|
|
|
'';
|
|
|
|
};
|
2014-08-23 16:04:34 +01:00
|
|
|
extraClasspathEntries = mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
Extra entries added to the Java classpath when running Riemann.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
extraJavaOpts = mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
Extra Java options used when launching Riemann.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2018-06-30 00:58:35 +01:00
|
|
|
users.groups.riemann.gid = config.ids.gids.riemann;
|
2014-08-23 16:04:34 +01:00
|
|
|
|
2018-06-30 00:58:35 +01:00
|
|
|
users.users.riemann = {
|
2014-08-23 16:04:34 +01:00
|
|
|
description = "riemann daemon user";
|
|
|
|
uid = config.ids.uids.riemann;
|
|
|
|
group = "riemann";
|
|
|
|
};
|
|
|
|
|
2018-08-01 13:36:16 +01:00
|
|
|
services.riemann.configFile = mkDefault (
|
|
|
|
writeText "riemann-config.clj" riemannConfig
|
|
|
|
);
|
|
|
|
|
2014-08-23 16:04:34 +01:00
|
|
|
systemd.services.riemann = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
path = [ inetutils ];
|
|
|
|
serviceConfig = {
|
|
|
|
User = "riemann";
|
|
|
|
ExecStart = "${launcher}/bin/riemann";
|
|
|
|
};
|
2018-08-01 13:36:16 +01:00
|
|
|
serviceConfig.LimitNOFILE = 65536;
|
2014-08-23 16:04:34 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|