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