1 { config, lib, pkgs, ...}:
5 cfg = config.services.hadoop;
6 hadoopConf = "${import ./conf.nix { inherit cfg pkgs lib; }}/";
7 mkIfNotNull = x: mkIf (x != null) x;
8 # generic hbase role options
9 hbaseRoleOption = name: extraOpts: {
10 enable = mkEnableOption "HBase ${name}";
12 openFirewall = mkOption {
15 description = "Open firewall ports for HBase ${name}.";
18 restartIfChanged = mkOption {
21 description = "Restart ${name} con config change.";
24 extraFlags = mkOption {
25 type = with types; listOf str;
27 example = literalExpression ''[ "--backup" ]'';
28 description = "Extra flags for the ${name} service.";
31 environment = mkOption {
32 type = with types; attrsOf str;
34 example = literalExpression ''
36 HBASE_MASTER_OPTS = "-Dcom.sun.management.jmxremote.ssl=true";
39 description = "Environment variables passed to ${name}.";
42 # generic hbase role configs
43 hbaseRoleConfig = name: ports: (mkIf cfg.hbase."${name}".enable {
44 services.hadoop.gatewayRole = {
46 enableHbaseCli = mkDefault true;
49 systemd.services."hbase-${toLower name}" = {
50 description = "HBase ${name}";
51 wantedBy = [ "multi-user.target" ];
52 path = with cfg; [ hbase.package ] ++ optional
53 (with cfg.hbase.master; enable && initHDFS) package;
54 preStart = mkIf (with cfg.hbase.master; enable && initHDFS)
55 (concatStringsSep "\n" (
56 map (x: "HADOOP_USER_NAME=hdfs hdfs --config /etc/hadoop-conf ${x}")[
57 "dfsadmin -safemode wait"
58 "dfs -mkdir -p ${cfg.hbase.rootdir}"
59 "dfs -chown hbase ${cfg.hbase.rootdir}"
63 inherit (cfg.hbase."${name}") environment;
64 script = concatStringsSep " " (
66 "hbase --config /etc/hadoop-conf/"
67 "${toLower name} start"
69 ++ cfg.hbase."${name}".extraFlags
70 ++ map (x: "--${toLower x} ${toString cfg.hbase.${name}.${x}}")
71 (filter (x: hasAttr x cfg.hbase.${name}) ["port" "infoPort"])
76 SyslogIdentifier = "hbase-${toLower name}";
81 services.hadoop.hbaseSiteInternal."hbase.rootdir" = cfg.hbase.rootdir;
84 firewall.allowedTCPPorts = mkIf cfg.hbase."${name}".openFirewall ports;
85 hosts = mkIf (with cfg.hbase.regionServer; enable && overrideHosts) {
86 "127.0.0.2" = mkForce [ ];
94 options.services.hadoop = {
96 gatewayRole.enableHbaseCli = mkEnableOption "HBase CLI tools";
98 hbaseSiteDefault = mkOption {
100 "hbase.regionserver.ipc.address" = "0.0.0.0";
101 "hbase.master.ipc.address" = "0.0.0.0";
102 "hbase.master.info.bindAddress" = "0.0.0.0";
103 "hbase.regionserver.info.bindAddress" = "0.0.0.0";
105 "hbase.cluster.distributed" = "true";
107 type = types.attrsOf types.anything;
109 Default options for hbase-site.xml
112 hbaseSite = mkOption {
114 type = with types; attrsOf anything;
115 example = literalExpression ''
117 "hbase.hregion.max.filesize" = 20*1024*1024*1024;
118 "hbase.table.normalization.enabled" = "true";
122 Additional options and overrides for hbase-site.xml
123 <https://github.com/apache/hbase/blob/rel/2.4.11/hbase-common/src/main/resources/hbase-default.xml>
126 hbaseSiteInternal = mkOption {
128 type = with types; attrsOf anything;
131 Internal option to add configs to hbase-site.xml based on module options
137 package = mkPackageOption pkgs "hbase" { };
141 This option will set "hbase.rootdir" in hbase-site.xml and determine
142 the directory shared by region servers and into which HBase persists.
143 The URL should be 'fully-qualified' to include the filesystem scheme.
144 If a core-site.xml is provided, the FS scheme defaults to the value
147 Filesystems other than HDFS (like S3, QFS, Swift) are also supported.
150 example = "hdfs://nameservice1/hbase";
153 zookeeperQuorum = mkOption {
155 This option will set "hbase.zookeeper.quorum" in hbase-site.xml.
156 Comma separated list of servers in the ZooKeeper ensemble.
158 type = with types; nullOr commas;
159 example = "zk1.internal,zk2.internal,zk3.internal";
163 ports = port: infoPort: {
167 description = "RPC port";
169 infoPort = mkOption {
172 description = "web UI port";
175 in mapAttrs hbaseRoleOption {
176 master.initHDFS = mkEnableOption "initialization of the hbase directory on HDFS";
177 regionServer.overrideHosts = mkOption {
181 Remove /etc/hosts entries for "127.0.0.2" and "::1" defined in nixos/modules/config/networking.nix
182 Regionservers must be able to resolve their hostnames to their IP addresses, through PTR records
183 or /etc/hosts entries.
186 thrift = ports 9090 9095;
187 rest = ports 8080 8085;
193 (mkIf cfg.gatewayRole.enable {
195 environment.systemPackages = mkIf cfg.gatewayRole.enableHbaseCli [ cfg.hbase.package ];
197 services.hadoop.hbaseSiteInternal = with cfg.hbase; {
198 "hbase.zookeeper.quorum" = mkIfNotNull zookeeperQuorum;
201 users.users.hbase = {
202 description = "Hadoop HBase user";
207 ] ++ (mapAttrsToList hbaseRoleConfig {
208 master = [ 16000 16010 ];
209 regionServer = [ 16020 16030 ];
210 thrift = with cfg.hbase.thrift; [ port infoPort ];
211 rest = with cfg.hbase.rest; [ port infoPort ];