8 cfg = config.services.hadoop;
9 hadoopConf = "${import ./conf.nix { inherit cfg pkgs lib; }}/";
10 restartIfChanged = lib.mkOption {
11 type = lib.types.bool;
13 Automatically restart the service on config change.
14 This can be set to false to defer restarts on clusters running critical applications.
15 Please consider the security implications of inadvertently running an older version,
16 and the possibility of unexpected behavior caused by inconsistent versions across a cluster when disabling this option.
20 extraFlags = lib.mkOption {
21 type = with lib.types; listOf str;
23 description = "Extra command line flags to pass to the service";
25 "-Dcom.sun.management.jmxremote"
26 "-Dcom.sun.management.jmxremote.port=8010"
29 extraEnv = lib.mkOption {
30 type = with lib.types; attrsOf str;
32 description = "Extra environment variables";
36 options.services.hadoop.yarn = {
38 enable = lib.mkEnableOption "Hadoop YARN ResourceManager";
39 inherit restartIfChanged extraFlags extraEnv;
41 openFirewall = lib.mkOption {
42 type = lib.types.bool;
45 Open firewall ports for resourcemanager
50 enable = lib.mkEnableOption "Hadoop YARN NodeManager";
51 inherit restartIfChanged extraFlags extraEnv;
54 cpuVCores = lib.mkOption {
55 description = "Number of vcores that can be allocated for containers.";
56 type = with lib.types; nullOr ints.positive;
59 maximumAllocationVCores = lib.mkOption {
60 description = "The maximum virtual CPU cores any container can be allocated.";
61 type = with lib.types; nullOr ints.positive;
64 memoryMB = lib.mkOption {
65 description = "Amount of physical memory, in MB, that can be allocated for containers.";
66 type = with lib.types; nullOr ints.positive;
69 maximumAllocationMB = lib.mkOption {
70 description = "The maximum physical memory any container can be allocated.";
71 type = with lib.types; nullOr ints.positive;
76 useCGroups = lib.mkOption {
77 type = lib.types.bool;
80 Use cgroups to enforce resource limits on containers
84 localDir = lib.mkOption {
85 description = "List of directories to store localized files in.";
86 type = with lib.types; nullOr (listOf path);
87 example = [ "/var/lib/hadoop/yarn/nm" ];
91 addBinBash = lib.mkOption {
92 type = lib.types.bool;
95 Add /bin/bash. This is needed by the linux container executor's launch script.
98 openFirewall = lib.mkOption {
99 type = lib.types.bool;
102 Open firewall ports for nodemanager.
103 Because containers can listen on any ephemeral port, TCP ports 1024–65535 will be opened.
109 config = lib.mkMerge [
110 (lib.mkIf cfg.gatewayRole.enable {
112 description = "Hadoop YARN user";
114 uid = config.ids.uids.yarn;
118 (lib.mkIf cfg.yarn.resourcemanager.enable {
119 systemd.services.yarn-resourcemanager = {
120 description = "Hadoop YARN ResourceManager";
121 wantedBy = [ "multi-user.target" ];
122 inherit (cfg.yarn.resourcemanager) restartIfChanged;
123 environment = cfg.yarn.resourcemanager.extraEnv;
127 SyslogIdentifier = "yarn-resourcemanager";
129 "${cfg.package}/bin/yarn --config ${hadoopConf} "
130 + " resourcemanager ${lib.escapeShellArgs cfg.yarn.resourcemanager.extraFlags}";
135 services.hadoop.gatewayRole.enable = true;
137 networking.firewall.allowedTCPPorts = (
138 lib.mkIf cfg.yarn.resourcemanager.openFirewall [
139 8088 # resourcemanager.webapp.address
140 8030 # resourcemanager.scheduler.address
141 8031 # resourcemanager.resource-tracker.address
142 8032 # resourcemanager.address
143 8033 # resourcemanager.admin.address
148 (lib.mkIf cfg.yarn.nodemanager.enable {
149 # Needed because yarn hardcodes /bin/bash in container start scripts
150 # These scripts can't be patched, they are generated at runtime
151 systemd.tmpfiles.rules = [
152 (lib.mkIf cfg.yarn.nodemanager.addBinBash "L /bin/bash - - - - /run/current-system/sw/bin/bash")
155 systemd.services.yarn-nodemanager = {
156 description = "Hadoop YARN NodeManager";
157 wantedBy = [ "multi-user.target" ];
158 inherit (cfg.yarn.nodemanager) restartIfChanged;
159 environment = cfg.yarn.nodemanager.extraEnv;
163 mkdir -p /var/log/hadoop/yarn/nodemanager
164 chown yarn:hadoop /var/log/hadoop/yarn/nodemanager
166 # set up setuid container executor binary
167 umount /run/wrappers/yarn-nodemanager/cgroup/cpu || true
168 rm -rf /run/wrappers/yarn-nodemanager/ || true
169 mkdir -p /run/wrappers/yarn-nodemanager/{bin,etc/hadoop,cgroup/cpu}
170 cp ${cfg.package}/bin/container-executor /run/wrappers/yarn-nodemanager/bin/
171 chgrp hadoop /run/wrappers/yarn-nodemanager/bin/container-executor
172 chmod 6050 /run/wrappers/yarn-nodemanager/bin/container-executor
173 cp ${hadoopConf}/container-executor.cfg /run/wrappers/yarn-nodemanager/etc/hadoop/
178 SyslogIdentifier = "yarn-nodemanager";
179 PermissionsStartOnly = true;
181 "${cfg.package}/bin/yarn --config ${hadoopConf} "
182 + " nodemanager ${lib.escapeShellArgs cfg.yarn.nodemanager.extraFlags}";
187 services.hadoop.gatewayRole.enable = true;
189 services.hadoop.yarnSiteInternal =
190 with cfg.yarn.nodemanager;
193 "yarn.nodemanager.local-dirs" = mkIf (localDir != null) (concatStringsSep "," localDir);
194 "yarn.scheduler.maximum-allocation-vcores" = resource.maximumAllocationVCores;
195 "yarn.scheduler.maximum-allocation-mb" = resource.maximumAllocationMB;
196 "yarn.nodemanager.resource.cpu-vcores" = resource.cpuVCores;
197 "yarn.nodemanager.resource.memory-mb" = resource.memoryMB;
200 "yarn.nodemanager.linux-container-executor.cgroups.hierarchy" = "/hadoop-yarn";
201 "yarn.nodemanager.linux-container-executor.resources-handler.class" =
202 "org.apache.hadoop.yarn.server.nodemanager.util.CgroupsLCEResourcesHandler";
203 "yarn.nodemanager.linux-container-executor.cgroups.mount" = "true";
204 "yarn.nodemanager.linux-container-executor.cgroups.mount-path" =
205 "/run/wrappers/yarn-nodemanager/cgroup";
209 networking.firewall.allowedTCPPortRanges = [
210 (lib.mkIf (cfg.yarn.nodemanager.openFirewall) {