at 21.11-pre 2.7 kB view raw
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 " " cfg.extraJavaOpts} \ 21 -cp ${classpath} \ 22 riemann.bin ${cfg.configFile} 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. For more complicated 41 config you should use configFile. 42 ''; 43 }; 44 configFiles = mkOption { 45 type = with types; listOf path; 46 default = []; 47 description = '' 48 Extra files containing Riemann configuration. These files will be 49 loaded at runtime by Riemann (with Clojure's 50 <literal>load-file</literal> function) at the end of the 51 configuration if you use the config option, this is ignored if you 52 use configFile. 53 ''; 54 }; 55 configFile = mkOption { 56 type = types.str; 57 description = '' 58 A Riemann config file. Any files in the same directory as this file 59 will be added to the classpath by Riemann. 60 ''; 61 }; 62 extraClasspathEntries = mkOption { 63 type = with types; listOf str; 64 default = []; 65 description = '' 66 Extra entries added to the Java classpath when running Riemann. 67 ''; 68 }; 69 extraJavaOpts = mkOption { 70 type = with types; listOf str; 71 default = []; 72 description = '' 73 Extra Java options used when launching Riemann. 74 ''; 75 }; 76 }; 77 }; 78 79 config = mkIf cfg.enable { 80 81 users.groups.riemann.gid = config.ids.gids.riemann; 82 83 users.users.riemann = { 84 description = "riemann daemon user"; 85 uid = config.ids.uids.riemann; 86 group = "riemann"; 87 }; 88 89 services.riemann.configFile = mkDefault ( 90 writeText "riemann-config.clj" riemannConfig 91 ); 92 93 systemd.services.riemann = { 94 wantedBy = [ "multi-user.target" ]; 95 path = [ inetutils ]; 96 serviceConfig = { 97 User = "riemann"; 98 ExecStart = "${launcher}/bin/riemann"; 99 }; 100 serviceConfig.LimitNOFILE = 65536; 101 }; 102 103 }; 104 105}