1 { config, lib, pkgs, ...}:
4 cfg = config.services.hadoop;
5 hadoopConf = "${import ./conf.nix { inherit cfg pkgs lib; }}/";
6 restartIfChanged = mkOption {
9 Automatically restart the service on config change.
10 This can be set to false to defer restarts on clusters running critical applications.
11 Please consider the security implications of inadvertently running an older version,
12 and the possibility of unexpected behavior caused by inconsistent versions across a cluster when disabling this option.
16 extraFlags = mkOption{
17 type = with types; listOf str;
19 description = "Extra command line flags to pass to the service";
21 "-Dcom.sun.management.jmxremote"
22 "-Dcom.sun.management.jmxremote.port=8010"
26 type = with types; attrsOf str;
28 description = "Extra environment variables";
32 options.services.hadoop.yarn = {
34 enable = mkEnableOption "Hadoop YARN ResourceManager";
35 inherit restartIfChanged extraFlags extraEnv;
37 openFirewall = mkOption {
41 Open firewall ports for resourcemanager
46 enable = mkEnableOption "Hadoop YARN NodeManager";
47 inherit restartIfChanged extraFlags extraEnv;
50 cpuVCores = mkOption {
51 description = "Number of vcores that can be allocated for containers.";
52 type = with types; nullOr ints.positive;
55 maximumAllocationVCores = mkOption {
56 description = "The maximum virtual CPU cores any container can be allocated.";
57 type = with types; nullOr ints.positive;
61 description = "Amount of physical memory, in MB, that can be allocated for containers.";
62 type = with types; nullOr ints.positive;
65 maximumAllocationMB = mkOption {
66 description = "The maximum physical memory any container can be allocated.";
67 type = with types; nullOr ints.positive;
72 useCGroups = mkOption {
76 Use cgroups to enforce resource limits on containers
81 description = "List of directories to store localized files in.";
82 type = with types; nullOr (listOf path);
83 example = [ "/var/lib/hadoop/yarn/nm" ];
87 addBinBash = mkOption {
91 Add /bin/bash. This is needed by the linux container executor's launch script.
94 openFirewall = mkOption {
98 Open firewall ports for nodemanager.
99 Because containers can listen on any ephemeral port, TCP ports 1024–65535 will be opened.
106 (mkIf cfg.gatewayRole.enable {
108 description = "Hadoop YARN user";
110 uid = config.ids.uids.yarn;
114 (mkIf cfg.yarn.resourcemanager.enable {
115 systemd.services.yarn-resourcemanager = {
116 description = "Hadoop YARN ResourceManager";
117 wantedBy = [ "multi-user.target" ];
118 inherit (cfg.yarn.resourcemanager) restartIfChanged;
119 environment = cfg.yarn.resourcemanager.extraEnv;
123 SyslogIdentifier = "yarn-resourcemanager";
124 ExecStart = "${cfg.package}/bin/yarn --config ${hadoopConf} " +
125 " resourcemanager ${escapeShellArgs cfg.yarn.resourcemanager.extraFlags}";
130 services.hadoop.gatewayRole.enable = true;
132 networking.firewall.allowedTCPPorts = (mkIf cfg.yarn.resourcemanager.openFirewall [
133 8088 # resourcemanager.webapp.address
134 8030 # resourcemanager.scheduler.address
135 8031 # resourcemanager.resource-tracker.address
136 8032 # resourcemanager.address
137 8033 # resourcemanager.admin.address
141 (mkIf cfg.yarn.nodemanager.enable {
142 # Needed because yarn hardcodes /bin/bash in container start scripts
143 # These scripts can't be patched, they are generated at runtime
144 systemd.tmpfiles.rules = [
145 (mkIf cfg.yarn.nodemanager.addBinBash "L /bin/bash - - - - /run/current-system/sw/bin/bash")
148 systemd.services.yarn-nodemanager = {
149 description = "Hadoop YARN NodeManager";
150 wantedBy = [ "multi-user.target" ];
151 inherit (cfg.yarn.nodemanager) restartIfChanged;
152 environment = cfg.yarn.nodemanager.extraEnv;
156 mkdir -p /var/log/hadoop/yarn/nodemanager
157 chown yarn:hadoop /var/log/hadoop/yarn/nodemanager
159 # set up setuid container executor binary
160 umount /run/wrappers/yarn-nodemanager/cgroup/cpu || true
161 rm -rf /run/wrappers/yarn-nodemanager/ || true
162 mkdir -p /run/wrappers/yarn-nodemanager/{bin,etc/hadoop,cgroup/cpu}
163 cp ${cfg.package}/bin/container-executor /run/wrappers/yarn-nodemanager/bin/
164 chgrp hadoop /run/wrappers/yarn-nodemanager/bin/container-executor
165 chmod 6050 /run/wrappers/yarn-nodemanager/bin/container-executor
166 cp ${hadoopConf}/container-executor.cfg /run/wrappers/yarn-nodemanager/etc/hadoop/
171 SyslogIdentifier = "yarn-nodemanager";
172 PermissionsStartOnly = true;
173 ExecStart = "${cfg.package}/bin/yarn --config ${hadoopConf} " +
174 " nodemanager ${escapeShellArgs cfg.yarn.nodemanager.extraFlags}";
179 services.hadoop.gatewayRole.enable = true;
181 services.hadoop.yarnSiteInternal = with cfg.yarn.nodemanager; mkMerge [ ({
182 "yarn.nodemanager.local-dirs" = mkIf (localDir!= null) (concatStringsSep "," localDir);
183 "yarn.scheduler.maximum-allocation-vcores" = resource.maximumAllocationVCores;
184 "yarn.scheduler.maximum-allocation-mb" = resource.maximumAllocationMB;
185 "yarn.nodemanager.resource.cpu-vcores" = resource.cpuVCores;
186 "yarn.nodemanager.resource.memory-mb" = resource.memoryMB;
187 }) (mkIf useCGroups {
188 "yarn.nodemanager.linux-container-executor.cgroups.hierarchy" = "/hadoop-yarn";
189 "yarn.nodemanager.linux-container-executor.resources-handler.class" = "org.apache.hadoop.yarn.server.nodemanager.util.CgroupsLCEResourcesHandler";
190 "yarn.nodemanager.linux-container-executor.cgroups.mount" = "true";
191 "yarn.nodemanager.linux-container-executor.cgroups.mount-path" = "/run/wrappers/yarn-nodemanager/cgroup";
194 networking.firewall.allowedTCPPortRanges = [
195 (mkIf (cfg.yarn.nodemanager.openFirewall) {from = 1024; to = 65535;})