at 23.11-pre 3.9 kB view raw
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 (lib.mdDoc '' 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 = mkOption { 50 type = types.package; 51 default = pkgs.hbase; 52 defaultText = literalExpression "pkgs.hbase"; 53 description = lib.mdDoc '' 54 HBase package to use. 55 ''; 56 }; 57 58 59 user = mkOption { 60 type = types.str; 61 default = "hbase"; 62 description = lib.mdDoc '' 63 User account under which HBase runs. 64 ''; 65 }; 66 67 group = mkOption { 68 type = types.str; 69 default = "hbase"; 70 description = lib.mdDoc '' 71 Group account under which HBase runs. 72 ''; 73 }; 74 75 dataDir = mkOption { 76 type = types.path; 77 default = "/var/lib/hbase"; 78 description = lib.mdDoc '' 79 Specifies location of HBase database files. This location should be 80 writable and readable for the user the HBase service runs as 81 (hbase by default). 82 ''; 83 }; 84 85 logDir = mkOption { 86 type = types.path; 87 default = "/var/log/hbase"; 88 description = lib.mdDoc '' 89 Specifies the location of HBase log files. 90 ''; 91 }; 92 93 settings = mkOption { 94 type = with lib.types; attrsOf (oneOf [ str int bool ]); 95 default = { 96 "hbase.rootdir" = "file://${cfg.dataDir}/hbase"; 97 "hbase.zookeeper.property.dataDir" = "${cfg.dataDir}/zookeeper"; 98 }; 99 defaultText = literalExpression '' 100 { 101 "hbase.rootdir" = "file://''${config.${opt.dataDir}}/hbase"; 102 "hbase.zookeeper.property.dataDir" = "''${config.${opt.dataDir}}/zookeeper"; 103 } 104 ''; 105 description = lib.mdDoc '' 106 configurations in hbase-site.xml, see <https://github.com/apache/hbase/blob/master/hbase-server/src/test/resources/hbase-site.xml> for details. 107 ''; 108 }; 109 110 }; 111 }; 112 113 ###### implementation 114 115 config = mkIf cfg.enable { 116 117 systemd.tmpfiles.rules = [ 118 "d '${cfg.dataDir}' - ${cfg.user} ${cfg.group} - -" 119 "d '${cfg.logDir}' - ${cfg.user} ${cfg.group} - -" 120 ]; 121 122 systemd.services.hbase = { 123 description = "HBase Server"; 124 wantedBy = [ "multi-user.target" ]; 125 126 environment = { 127 # JRE 15 removed option `UseConcMarkSweepGC` which is needed. 128 JAVA_HOME = "${pkgs.jre8}"; 129 HBASE_LOG_DIR = cfg.logDir; 130 }; 131 132 serviceConfig = { 133 User = cfg.user; 134 Group = cfg.group; 135 ExecStart = "${cfg.package}/bin/hbase --config ${configDir} master start"; 136 }; 137 }; 138 139 users.users.hbase = { 140 description = "HBase Server user"; 141 group = "hbase"; 142 uid = config.ids.uids.hbase; 143 }; 144 145 users.groups.hbase.gid = config.ids.gids.hbase; 146 147 }; 148}