1{
2 config,
3 pkgs,
4 lib,
5 ...
6}:
7let
8
9 cfg = config.services.riemann;
10
11 classpath = lib.concatStringsSep ":" (
12 cfg.extraClasspathEntries ++ [ "${pkgs.riemann}/share/java/riemann.jar" ]
13 );
14
15 riemannConfig = lib.concatStringsSep "\n" (
16 [ cfg.config ] ++ (map (f: ''(load-file "${f}")'') cfg.configFiles)
17 );
18
19 launcher = pkgs.writeScriptBin "riemann" ''
20 #!/bin/sh
21 exec ${pkgs.jdk}/bin/java ${lib.concatStringsSep " " cfg.extraJavaOpts} \
22 -cp ${classpath} \
23 riemann.bin ${cfg.configFile}
24 '';
25
26in
27{
28
29 options = {
30
31 services.riemann = {
32 enable = lib.mkEnableOption "Riemann network monitoring daemon";
33
34 config = lib.mkOption {
35 type = lib.types.lines;
36 description = ''
37 Contents of the Riemann configuration file. For more complicated
38 config you should use configFile.
39 '';
40 };
41 configFiles = lib.mkOption {
42 type = with lib.types; listOf path;
43 default = [ ];
44 description = ''
45 Extra files containing Riemann configuration. These files will be
46 loaded at runtime by Riemann (with Clojure's
47 `load-file` function) at the end of the
48 configuration if you use the config option, this is ignored if you
49 use configFile.
50 '';
51 };
52 configFile = lib.mkOption {
53 type = lib.types.str;
54 description = ''
55 A Riemann config file. Any files in the same directory as this file
56 will be added to the classpath by Riemann.
57 '';
58 };
59 extraClasspathEntries = lib.mkOption {
60 type = with lib.types; listOf str;
61 default = [ ];
62 description = ''
63 Extra entries added to the Java classpath when running Riemann.
64 '';
65 };
66 extraJavaOpts = lib.mkOption {
67 type = with lib.types; listOf str;
68 default = [ ];
69 description = ''
70 Extra Java options used when launching Riemann.
71 '';
72 };
73 };
74 };
75
76 config = lib.mkIf cfg.enable {
77
78 users.groups.riemann.gid = config.ids.gids.riemann;
79
80 users.users.riemann = {
81 description = "riemann daemon user";
82 uid = config.ids.uids.riemann;
83 group = "riemann";
84 };
85
86 services.riemann.configFile = lib.mkDefault (pkgs.writeText "riemann-config.clj" riemannConfig);
87
88 systemd.services.riemann = {
89 wantedBy = [ "multi-user.target" ];
90 path = [ pkgs.inetutils ];
91 serviceConfig = {
92 User = "riemann";
93 ExecStart = "${launcher}/bin/riemann";
94 };
95 serviceConfig.LimitNOFILE = 65536;
96 };
97
98 };
99
100}