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