-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflake.nix
219 lines (194 loc) · 7.83 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
{
description = "Apache Hive is a SQL interface to tables in HDFS.";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-22.11";
# nixpkgs.url = "/home/sahiti/work/nixpkgs";
utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, utils }: utils.lib.eachDefaultSystem
(system:
let pkgs = import nixpkgs { inherit system; };
in
rec {
defaultPackage = packages.hive;
packages = {
hive = pkgs.callPackage ./default.nix { jdk = pkgs.jdk8; }; # TODO make jdk version configurable
# oozie = pkgs.callPackage ./oozie.nix { jdk = pkgs.jdk8; }; not packaging oozie. it isn't even compatible with hadoop 3.
};
checks =
let test = name: file: import file {
inherit pkgs;
makeTest = import (nixpkgs + "/nixos/tests/make-test-python.nix");
flake = self;
package = defaultPackage;
};
in
pkgs.lib.mapAttrs test {
standalone-tests = ./test.nix;
hadoop-tests = ./full-hadoop-test.nix;
hadoop-integration-tests = ./test-with-hadoop.nix;
kerberos-integration-tests = ./test-with-kerberos.nix;
};
}) // {
nixosModules = {
kerberos = ./kerberos-module.nix;
hadoop-kerberos = ./hadoop-kerberos-module.nix;
hiveserver = { config, lib, pkgs, ... }:
with lib;
let cfg = config.services.hadoop.hiveserver;
in
{
options.services.hadoop.hiveserver = {
enable = mkEnableOption "enable hiveserver";
metastore = {
enable = mkEnableOption "enable metastore. not actually used, right now metastore is active wherever server is.";
openFirewall = mkEnableOption "open firewall ports for metastore";
};
openFirewall = mkEnableOption "open firewall ports for hiveserver webUI and JDBC connection.";
user = mkOption {
type = types.str;
default = "hive";
description = "user that hive services run with";
};
group = mkOption {
type = types.str;
default = "hadoop";
description = "group that hive services run with";
};
hiveSite = mkOption {
default = { };
type = types.attrsOf types.anything;
example = literalExpression ''
{
"fs.defaultFS" = "hdfs://localhost";
}
'';
description = ''
Hive configuration hive-site.xml definition
<link xlink:href="https://cwiki.apache.org/confluence/display/Hive/AdminManual+Configuration"/>
'';
};
hiveSiteDefault = mkOption {
default = {
"hive.server2.enable.doAs" = "false";
# https://issues.apache.org/jira/browse/HIVE-19740
"hadoop.proxyuser.hive.hosts" = "HS2_HOST";
"hadoop.proxyuser.hive.groups" = "*";
"hive.metastore.event.db.notification.api.auth" = "false";
};
type = types.attrsOf types.anything;
example = literalExpression ''
{
"fs.defaultFS" = "hdfs://localhost";
}
'';
description = ''
Hive configuration hive-site.xml definition
<link xlink:href="https://cwiki.apache.org/confluence/display/Hive/AdminManual+Configuration"/>
'';
};
gatewayRole.enable = mkEnableOption "gateway role for deploying hive configs to toher nodes";
};
config = mkMerge [
(mkIf cfg.gatewayRole.enable {
users.users.${config.services.hadoop.hiveserver.user} = {
description = "hive user";
isSystemUser = true;
group = config.services.hadoop.hiveserver.group;
};
environment.systemPackages = [
self.defaultPackage.${config.nixpkgs.system}
];
})
(mkIf cfg.enable {
environment.systemPackages = [
self.defaultPackage.${config.nixpkgs.system}
];
networking.firewall.allowedTCPPorts = (mkIf cfg.openFirewall [ 10000 10001 10002 14000 ]) // (mkIf cfg.metastore.openFirewall [ 9083 ]);
users.users.${config.services.hadoop.hiveserver.user} = {
description = "hive user";
isSystemUser = true;
group = config.services.hadoop.hiveserver.group;
};
services.hadoop = {
extraConfDirs = let
propertyXml = name: value: lib.optionalString (value != null) ''
<property>
<name>${name}</name>
<value>${builtins.toString value}</value>
</property>
'';
siteXml = fileName: properties: pkgs.writeTextDir fileName ''
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- generated by NixOS -->
<configuration>
${builtins.concatStringsSep "\n" (pkgs.lib.mapAttrsToList propertyXml properties)}
</configuration>
'';
in
[
(pkgs.runCommand "hive-conf" { }
(with cfg; ''
mkdir -p $out/
cp ${siteXml "hive-site.xml" (hiveSiteDefault // hiveSite)}/* $out/
cp ${siteXml "metastore-site.xml" (hiveSiteDefault // hiveSite)}/* $out/
''))
];
gatewayRole.enable = true;
};
systemd.services = {
hive-init = {
wantedBy = [ "multi-user.target" ];
path = [ pkgs.hadoop pkgs.sudo pkgs.coreutils config.krb5.kerberos ];
script = ''
# in future to be escaped with a kerberos enable option
# kinit -k -t /var/security/keytab/hiveserver.service.keytab hive/hiveserver
sudo -u hdfs hadoop fs -mkdir -p /home/hive || true
sudo -u hdfs hadoop fs -chown ${config.services.hadoop.hiveserver.user}:${config.services.hadoop.hiveserver.group} /home/hive || true
sudo -u hdfs hadoop fs -mkdir /tmp || true
sudo -u hdfs hadoop fs -chown hdfs:${config.services.hadoop.hiveserver.group} /tmp || true
sudo -u hdfs hadoop fs -chmod g+w /tmp || true
sudo -u hdfs hadoop fs -mkdir -p /user/hive || true
sudo -u hdfs hadoop fs -chown ${config.services.hadoop.hiveserver.user}:${config.services.hadoop.hiveserver.group} /user/hive || true
sudo -u hdfs hadoop fs -mkdir /user/hive/warehouse || true
sudo -u hdfs hadoop fs -chown ${config.services.hadoop.hiveserver.user}:${config.services.hadoop.hiveserver.group} /user/hive/warehouse || true
sudo -u hdfs hadoop fs -chmod g+w /user/hive/warehouse || true
mkdir /var/run/hive || true
chown ${config.services.hadoop.hiveserver.user}:${config.services.hadoop.hiveserver.group} /var/run/hive || true
'';
serviceConfig = {
Type = "oneshot";
# The below are the instructions to initialize Hive resoruces given in https://cwiki.apache.org/confluence/display/Hive/GettingStarted#GettingStarted-RunningHiveServer2andBeeline.
};
};
hiveserver = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" "hive-init.service" ];
environment.HADOOP_CONF_DIR = "/etc/hadoop-conf";
script = ''
hiveserver2 --hiveconf hive.root.logger=INFO,console
'';
path = with pkgs; [ self.defaultPackage.${config.nixpkgs.system} sudo coreutils bash which gawk psutils ];
serviceConfig = {
User = config.services.hadoop.hiveserver.user;
};
};
hivemetastore = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" "hive-init.service" ];
environment.HADOOP_CONF_DIR = "/etc/hadoop-conf";
script = ''
hive --service metastore --hiveconf hive.root.logger=INFO,console
'';
path = with pkgs; [ self.defaultPackage.${config.nixpkgs.system} sudo coreutils bash which gawk psutils ];
serviceConfig = {
User = config.services.hadoop.hiveserver.user;
};
};
};
})
];
};
};
};
}