1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.hbase;
7
8 defaultConfig = {
9 "hbase.rootdir" = "file://${cfg.dataDir}/hbase";
10 "hbase.zookeeper.property.dataDir" = "${cfg.dataDir}/zookeeper";
11 };
12
13 buildProperty = configAttr:
14 (builtins.concatStringsSep "\n"
15 (lib.mapAttrsToList
16 (name: value: ''
17 <property>
18 <name>${name}</name>
19 <value>${builtins.toString value}</value>
20 </property>
21 '')
22 configAttr));
23
24 configFile = pkgs.writeText "hbase-site.xml"
25 ''<configuration>
26 ${buildProperty (defaultConfig // cfg.settings)}
27 </configuration>
28 '';
29
30 configDir = pkgs.runCommand "hbase-config-dir" { preferLocalBuild = true; } ''
31 mkdir -p $out
32 cp ${cfg.package}/conf/* $out/
33 rm $out/hbase-site.xml
34 ln -s ${configFile} $out/hbase-site.xml
35 '' ;
36
37in {
38
39 ###### interface
40
41 options = {
42
43 services.hbase = {
44
45 enable = mkOption {
46 type = types.bool;
47 default = false;
48 description = ''
49 Whether to run HBase.
50 '';
51 };
52
53 package = mkOption {
54 type = types.package;
55 default = pkgs.hbase;
56 defaultText = literalExpression "pkgs.hbase";
57 description = ''
58 HBase package to use.
59 '';
60 };
61
62
63 user = mkOption {
64 type = types.str;
65 default = "hbase";
66 description = ''
67 User account under which HBase runs.
68 '';
69 };
70
71 group = mkOption {
72 type = types.str;
73 default = "hbase";
74 description = ''
75 Group account under which HBase runs.
76 '';
77 };
78
79 dataDir = mkOption {
80 type = types.path;
81 default = "/var/lib/hbase";
82 description = ''
83 Specifies location of HBase database files. This location should be
84 writable and readable for the user the HBase service runs as
85 (hbase by default).
86 '';
87 };
88
89 logDir = mkOption {
90 type = types.path;
91 default = "/var/log/hbase";
92 description = ''
93 Specifies the location of HBase log files.
94 '';
95 };
96
97 settings = mkOption {
98 type = with lib.types; attrsOf (oneOf [ str int bool ]);
99 default = defaultConfig;
100 description = ''
101 configurations in hbase-site.xml, see <link xlink:href="https://github.com/apache/hbase/blob/master/hbase-server/src/test/resources/hbase-site.xml"/> for details.
102 '';
103 };
104
105 };
106
107 };
108
109 ###### implementation
110
111 config = mkIf config.services.hbase.enable {
112
113 systemd.tmpfiles.rules = [
114 "d '${cfg.dataDir}' - ${cfg.user} ${cfg.group} - -"
115 "d '${cfg.logDir}' - ${cfg.user} ${cfg.group} - -"
116 ];
117
118 systemd.services.hbase = {
119 description = "HBase Server";
120 wantedBy = [ "multi-user.target" ];
121
122 environment = {
123 # JRE 15 removed option `UseConcMarkSweepGC` which is needed.
124 JAVA_HOME = "${pkgs.jre8}";
125 HBASE_LOG_DIR = cfg.logDir;
126 };
127
128 serviceConfig = {
129 User = cfg.user;
130 Group = cfg.group;
131 ExecStart = "${cfg.package}/bin/hbase --config ${configDir} master start";
132 };
133 };
134
135 users.users.hbase = {
136 description = "HBase Server user";
137 group = "hbase";
138 uid = config.ids.uids.hbase;
139 };
140
141 users.groups.hbase.gid = config.ids.gids.hbase;
142
143 };
144}