at 21.11-pre 2.8 kB view raw
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" { preferLocalBuild = true; } '' 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.str; 57 default = "hbase"; 58 description = '' 59 User account under which HBase runs. 60 ''; 61 }; 62 63 group = mkOption { 64 type = types.str; 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.tmpfiles.rules = [ 98 "d '${cfg.dataDir}' - ${cfg.user} ${cfg.group} - -" 99 "d '${cfg.logDir}' - ${cfg.user} ${cfg.group} - -" 100 ]; 101 102 systemd.services.hbase = { 103 description = "HBase Server"; 104 wantedBy = [ "multi-user.target" ]; 105 106 environment = { 107 JAVA_HOME = "${pkgs.jre}"; 108 HBASE_LOG_DIR = cfg.logDir; 109 }; 110 111 serviceConfig = { 112 User = cfg.user; 113 Group = cfg.group; 114 ExecStart = "${cfg.package}/bin/hbase --config ${configDir} master start"; 115 }; 116 }; 117 118 users.users.hbase = { 119 description = "HBase Server user"; 120 group = "hbase"; 121 uid = config.ids.uids.hbase; 122 }; 123 124 users.groups.hbase.gid = config.ids.gids.hbase; 125 126 }; 127}