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