at 17.09-beta 2.4 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.opentsdb; 7 8 configFile = pkgs.writeText "opentsdb.conf" cfg.config; 9 10in { 11 12 ###### interface 13 14 options = { 15 16 services.opentsdb = { 17 18 enable = mkOption { 19 type = types.bool; 20 default = false; 21 description = '' 22 Whether to run OpenTSDB. 23 ''; 24 }; 25 26 package = mkOption { 27 type = types.package; 28 default = pkgs.opentsdb; 29 defaultText = "pkgs.opentsdb"; 30 example = literalExample "pkgs.opentsdb"; 31 description = '' 32 OpenTSDB package to use. 33 ''; 34 }; 35 36 user = mkOption { 37 type = types.string; 38 default = "opentsdb"; 39 description = '' 40 User account under which OpenTSDB runs. 41 ''; 42 }; 43 44 group = mkOption { 45 type = types.string; 46 default = "opentsdb"; 47 description = '' 48 Group account under which OpenTSDB runs. 49 ''; 50 }; 51 52 port = mkOption { 53 type = types.int; 54 default = 4242; 55 description = '' 56 Which port OpenTSDB listens on. 57 ''; 58 }; 59 60 config = mkOption { 61 type = types.lines; 62 default = '' 63 tsd.core.auto_create_metrics = true 64 tsd.http.request.enable_chunked = true 65 ''; 66 description = '' 67 The contents of OpenTSDB's configuration file 68 ''; 69 }; 70 71 }; 72 73 }; 74 75 ###### implementation 76 77 config = mkIf config.services.opentsdb.enable { 78 79 systemd.services.opentsdb = { 80 description = "OpenTSDB Server"; 81 wantedBy = [ "multi-user.target" ]; 82 requires = [ "hbase.service" ]; 83 84 environment.JAVA_HOME = "${pkgs.jre}"; 85 path = [ pkgs.gnuplot ]; 86 87 preStart = 88 '' 89 COMPRESSION=NONE HBASE_HOME=${config.services.hbase.package} ${cfg.package}/share/opentsdb/tools/create_table.sh 90 ''; 91 92 serviceConfig = { 93 PermissionsStartOnly = true; 94 User = cfg.user; 95 Group = cfg.group; 96 ExecStart = "${cfg.package}/bin/tsdb tsd --staticroot=${cfg.package}/share/opentsdb/static --cachedir=/tmp/opentsdb --port=${toString cfg.port} --config=${configFile}"; 97 }; 98 }; 99 100 users.extraUsers.opentsdb = { 101 description = "OpenTSDB Server user"; 102 group = "opentsdb"; 103 uid = config.ids.uids.opentsdb; 104 }; 105 106 users.extraGroups.opentsdb.gid = config.ids.gids.opentsdb; 107 108 }; 109}