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 defaultText = "pkgs.hbase";
48 example = literalExample "pkgs.hbase";
49 description = ''
50 HBase package to use.
51 '';
52 };
53
54
55 user = mkOption {
56 type = types.string;
57 default = "hbase";
58 description = ''
59 User account under which HBase runs.
60 '';
61 };
62
63 group = mkOption {
64 type = types.string;
65 default = "hbase";
66 description = ''
67 Group account under which HBase runs.
68 '';
69 };
70
71 dataDir = mkOption {
72 type = 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 = mkOption {
82 type = types.path;
83 default = "/var/log/hbase";
84 description = ''
85 Specifies the location of HBase log files.
86 '';
87 };
88
89 };
90
91 };
92
93 ###### implementation
94
95 config = mkIf config.services.hbase.enable {
96
97 systemd.services.hbase = {
98 description = "HBase Server";
99 wantedBy = [ "multi-user.target" ];
100
101 environment = {
102 JAVA_HOME = "${pkgs.jre}";
103 HBASE_LOG_DIR = cfg.logDir;
104 };
105
106 preStart =
107 ''
108 mkdir -p ${cfg.dataDir};
109 mkdir -p ${cfg.logDir};
110
111 if [ "$(id -u)" = 0 ]; then
112 chown ${cfg.user}:${cfg.group} ${cfg.dataDir}
113 chown ${cfg.user}:${cfg.group} ${cfg.logDir}
114 fi
115 '';
116
117 serviceConfig = {
118 PermissionsStartOnly = true;
119 User = cfg.user;
120 Group = cfg.group;
121 ExecStart = "${cfg.package}/bin/hbase --config ${configDir} master start";
122 };
123 };
124
125 users.extraUsers.hbase = {
126 description = "HBase Server user";
127 group = "hbase";
128 uid = config.ids.uids.hbase;
129 };
130
131 users.extraGroups.hbase.gid = config.ids.gids.hbase;
132
133 };
134}