at 23.11-pre 2.3 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 = mkEnableOption (lib.mdDoc "OpenTSDB"); 19 20 package = mkOption { 21 type = types.package; 22 default = pkgs.opentsdb; 23 defaultText = literalExpression "pkgs.opentsdb"; 24 description = lib.mdDoc '' 25 OpenTSDB package to use. 26 ''; 27 }; 28 29 user = mkOption { 30 type = types.str; 31 default = "opentsdb"; 32 description = lib.mdDoc '' 33 User account under which OpenTSDB runs. 34 ''; 35 }; 36 37 group = mkOption { 38 type = types.str; 39 default = "opentsdb"; 40 description = lib.mdDoc '' 41 Group account under which OpenTSDB runs. 42 ''; 43 }; 44 45 port = mkOption { 46 type = types.port; 47 default = 4242; 48 description = lib.mdDoc '' 49 Which port OpenTSDB listens on. 50 ''; 51 }; 52 53 config = mkOption { 54 type = types.lines; 55 default = '' 56 tsd.core.auto_create_metrics = true 57 tsd.http.request.enable_chunked = true 58 ''; 59 description = lib.mdDoc '' 60 The contents of OpenTSDB's configuration file 61 ''; 62 }; 63 64 }; 65 66 }; 67 68 ###### implementation 69 70 config = mkIf config.services.opentsdb.enable { 71 72 systemd.services.opentsdb = { 73 description = "OpenTSDB Server"; 74 wantedBy = [ "multi-user.target" ]; 75 requires = [ "hbase.service" ]; 76 77 environment.JAVA_HOME = "${pkgs.jre}"; 78 path = [ pkgs.gnuplot ]; 79 80 preStart = 81 '' 82 COMPRESSION=NONE HBASE_HOME=${config.services.hbase.package} ${cfg.package}/share/opentsdb/tools/create_table.sh 83 ''; 84 85 serviceConfig = { 86 PermissionsStartOnly = true; 87 User = cfg.user; 88 Group = cfg.group; 89 ExecStart = "${cfg.package}/bin/tsdb tsd --staticroot=${cfg.package}/share/opentsdb/static --cachedir=/tmp/opentsdb --port=${toString cfg.port} --config=${configFile}"; 90 }; 91 }; 92 93 users.users.opentsdb = { 94 description = "OpenTSDB Server user"; 95 group = "opentsdb"; 96 uid = config.ids.uids.opentsdb; 97 }; 98 99 users.groups.opentsdb.gid = config.ids.gids.opentsdb; 100 101 }; 102}