at 25.11-pre 1.7 kB view raw
1{ 2 config, 3 pkgs, 4 lib, 5 ... 6}: 7let 8 9 cfg = config.services.riemann-tools; 10 11 riemannHost = "${cfg.riemannHost}"; 12 13 healthLauncher = pkgs.writeScriptBin "riemann-health" '' 14 #!/bin/sh 15 exec ${pkgs.riemann-tools}/bin/riemann-health ${builtins.concatStringsSep " " cfg.extraArgs} --host ${riemannHost} 16 ''; 17 18in 19{ 20 21 options = { 22 23 services.riemann-tools = { 24 enableHealth = lib.mkOption { 25 type = lib.types.bool; 26 default = false; 27 description = '' 28 Enable the riemann-health daemon. 29 ''; 30 }; 31 riemannHost = lib.mkOption { 32 type = lib.types.str; 33 default = "127.0.0.1"; 34 description = '' 35 Address of the host riemann node. Defaults to localhost. 36 ''; 37 }; 38 extraArgs = lib.mkOption { 39 type = lib.types.listOf lib.types.str; 40 default = [ ]; 41 description = '' 42 A list of commandline-switches forwarded to a riemann-tool. 43 See for example `riemann-health --help` for available options. 44 ''; 45 example = [ 46 "-p 5555" 47 "--timeout=30" 48 "--attribute=myattribute=42" 49 ]; 50 }; 51 }; 52 }; 53 54 config = lib.mkIf cfg.enableHealth { 55 56 users.groups.riemanntools.gid = config.ids.gids.riemanntools; 57 58 users.users.riemanntools = { 59 description = "riemann-tools daemon user"; 60 uid = config.ids.uids.riemanntools; 61 group = "riemanntools"; 62 }; 63 64 systemd.services.riemann-health = { 65 wantedBy = [ "multi-user.target" ]; 66 path = [ pkgs.procps ]; 67 serviceConfig = { 68 User = "riemanntools"; 69 ExecStart = "${healthLauncher}/bin/riemann-health"; 70 }; 71 }; 72 73 }; 74 75}