1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.hbase;
7
8 configFile = pkgs.writeText "hbase-site.xml" ''
9 <configuration>
10 <property>
11 <name>hbase.rootdir</name>
12 <value>file://${cfg.dataDir}/hbase</value>
13 </property>
14 <property>
15 <name>hbase.zookeeper.property.dataDir</name>
16 <value>${cfg.dataDir}/zookeeper</value>
17 </property>
18 </configuration>
19 '';
20
21 configDir = pkgs.runCommand "hbase-config-dir" {} ''
22 mkdir -p $out
23 cp ${cfg.package}/conf/* $out/
24 rm $out/hbase-site.xml
25 ln -s ${configFile} $out/hbase-site.xml
26 '' ;
27
28in {
29
30 ###### interface
31
32 options = {
33
34 services.hbase = {
35
36 enable = mkOption {
37 type = types.bool;
38 default = false;
39 description = ''
40 Whether to run HBase.
41 '';
42 };
43
44 package = mkOption {
45 type = types.package;
46 default = pkgs.hbase;
47 example = literalExample "pkgs.hbase";
48 description = ''
49 HBase package to use.
50 '';
51 };
52
53
54 user = mkOption {
55 type = types.string;
56 default = "hbase";
57 description = ''
58 User account under which HBase runs.
59 '';
60 };
61
62 group = mkOption {
63 type = types.string;
64 default = "hbase";
65 description = ''
66 Group account under which HBase runs.
67 '';
68 };
69
70 dataDir = mkOption {
71 type = types.path;
72 default = "/var/lib/hbase";
73 description = ''
74 Specifies location of HBase database files. This location should be
75 writable and readable for the user the HBase service runs as
76 (hbase by default).
77 '';
78 };
79
80 logDir = mkOption {
81 type = types.path;
82 default = "/var/log/hbase";
83 description = ''
84 Specifies the location of HBase log files.
85 '';
86 };
87
88 };
89
90 };
91
92 ###### implementation
93
94 config = mkIf config.services.hbase.enable {
95
96 systemd.services.hbase = {
97 description = "HBase Server";
98 wantedBy = [ "multi-user.target" ];
99
100 environment = {
101 JAVA_HOME = "${pkgs.jre}";
102 HBASE_LOG_DIR = cfg.logDir;
103 };
104
105 preStart =
106 ''
107 mkdir -p ${cfg.dataDir};
108 mkdir -p ${cfg.logDir};
109
110 if [ "$(id -u)" = 0 ]; then
111 chown ${cfg.user}:${cfg.group} ${cfg.dataDir}
112 chown ${cfg.user}:${cfg.group} ${cfg.logDir}
113 fi
114 '';
115
116 serviceConfig = {
117 PermissionsStartOnly = true;
118 User = cfg.user;
119 Group = cfg.group;
120 ExecStart = "${cfg.package}/bin/hbase --config ${configDir} master start";
121 };
122 };
123
124 users.extraUsers.hbase = {
125 description = "HBase Server user";
126 group = "hbase";
127 uid = config.ids.uids.hbase;
128 };
129
130 users.extraGroups.hbase.gid = config.ids.gids.hbase;
131
132 };
133}