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