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