1{ cfg, pkgs, lib }:
2let
3 propertyXml = name: value: lib.optionalString (value != null) ''
4 <property>
5 <name>${name}</name>
6 <value>${builtins.toString value}</value>
7 </property>
8 '';
9 siteXml = fileName: properties: pkgs.writeTextDir fileName ''
10 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
11 <!-- generated by NixOS -->
12 <configuration>
13 ${builtins.concatStringsSep "\n" (pkgs.lib.mapAttrsToList propertyXml properties)}
14 </configuration>
15 '';
16 cfgLine = name: value: ''
17 ${name}=${builtins.toString value}
18 '';
19 cfgFile = fileName: properties: pkgs.writeTextDir fileName ''
20 # generated by NixOS
21 ${builtins.concatStringsSep "" (pkgs.lib.mapAttrsToList cfgLine properties)}
22 '';
23 userFunctions = ''
24 hadoop_verify_logdir() {
25 echo Skipping verification of log directory
26 }
27 '';
28 hadoopEnv = ''
29 export HADOOP_LOG_DIR=/tmp/hadoop/$USER
30 '';
31in
32pkgs.runCommand "hadoop-conf" {} (with cfg; ''
33 mkdir -p $out/
34 cp ${siteXml "core-site.xml" (coreSite // coreSiteInternal)}/* $out/
35 cp ${siteXml "hdfs-site.xml" (hdfsSiteDefault // hdfsSite // hdfsSiteInternal)}/* $out/
36 cp ${siteXml "hbase-site.xml" (hbaseSiteDefault // hbaseSite // hbaseSiteInternal)}/* $out/
37 cp ${siteXml "mapred-site.xml" (mapredSiteDefault // mapredSite)}/* $out/
38 cp ${siteXml "yarn-site.xml" (yarnSiteDefault // yarnSite // yarnSiteInternal)}/* $out/
39 cp ${siteXml "httpfs-site.xml" httpfsSite}/* $out/
40 cp ${cfgFile "container-executor.cfg" containerExecutorCfg}/* $out/
41 cp ${pkgs.writeTextDir "hadoop-user-functions.sh" userFunctions}/* $out/
42 cp ${pkgs.writeTextDir "hadoop-env.sh" hadoopEnv}/* $out/
43 cp ${log4jProperties} $out/log4j.properties
44 ${lib.concatMapStringsSep "\n" (dir: "cp -f -r ${dir}/* $out/") extraConfDirs}
45'')