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