at 18.09-beta 1.9 kB view raw
1{ config, pkgs, lib, ... }: 2 3with pkgs; 4with lib; 5 6let 7 8 cfg = config.services.riemann-dash; 9 10 conf = writeText "config.rb" '' 11 riemann_base = "${cfg.dataDir}" 12 config.store[:ws_config] = "#{riemann_base}/config/config.json" 13 ${cfg.config} 14 ''; 15 16 launcher = writeScriptBin "riemann-dash" '' 17 #!/bin/sh 18 exec ${pkgs.riemann-dash}/bin/riemann-dash ${conf} 19 ''; 20 21in { 22 23 options = { 24 25 services.riemann-dash = { 26 enable = mkOption { 27 type = types.bool; 28 default = false; 29 description = '' 30 Enable the riemann-dash dashboard daemon. 31 ''; 32 }; 33 config = mkOption { 34 type = types.lines; 35 description = '' 36 Contents added to the end of the riemann-dash configuration file. 37 ''; 38 }; 39 dataDir = mkOption { 40 type = types.str; 41 default = "/var/riemann-dash"; 42 description = '' 43 Location of the riemann-base dir. The dashboard configuration file is 44 is stored to this directory. The directory is created automatically on 45 service start, and owner is set to the riemanndash user. 46 ''; 47 }; 48 }; 49 50 }; 51 52 config = mkIf cfg.enable { 53 54 users.groups.riemanndash.gid = config.ids.gids.riemanndash; 55 56 users.users.riemanndash = { 57 description = "riemann-dash daemon user"; 58 uid = config.ids.uids.riemanndash; 59 group = "riemanndash"; 60 }; 61 62 systemd.services.riemann-dash = { 63 wantedBy = [ "multi-user.target" ]; 64 wants = [ "riemann.service" ]; 65 after = [ "riemann.service" ]; 66 preStart = '' 67 mkdir -p ${cfg.dataDir}/config 68 chown -R riemanndash:riemanndash ${cfg.dataDir} 69 ''; 70 serviceConfig = { 71 User = "riemanndash"; 72 ExecStart = "${launcher}/bin/riemann-dash"; 73 PermissionsStartOnly = true; 74 }; 75 }; 76 77 }; 78 79}