1 {config, pkgs, lib, ...}:
3 cfg = config.services.spark;
10 enable = mkEnableOption (lib.mdDoc "Spark master service");
13 description = lib.mdDoc "Address the spark master binds to.";
14 default = "127.0.0.1";
17 restartIfChanged = mkOption {
19 description = lib.mdDoc ''
20 Automatically restart master service on config change.
21 This can be set to false to defer restarts on clusters running critical applications.
22 Please consider the security implications of inadvertently running an older version,
23 and the possibility of unexpected behavior caused by inconsistent versions across a cluster when disabling this option.
27 extraEnvironment = mkOption {
28 type = types.attrsOf types.str;
29 description = lib.mdDoc "Extra environment variables to pass to spark master. See spark-standalone documentation.";
32 SPARK_MASTER_WEBUI_PORT = 8181;
33 SPARK_MASTER_OPTS = "-Dspark.deploy.defaultCores=5";
38 enable = mkEnableOption (lib.mdDoc "Spark worker service");
41 description = lib.mdDoc "Spark worker work dir.";
42 default = "/var/lib/spark";
46 description = lib.mdDoc "Address of the spark master.";
47 default = "127.0.0.1:7077";
49 restartIfChanged = mkOption {
51 description = lib.mdDoc ''
52 Automatically restart worker service on config change.
53 This can be set to false to defer restarts on clusters running critical applications.
54 Please consider the security implications of inadvertently running an older version,
55 and the possibility of unexpected behavior caused by inconsistent versions across a cluster when disabling this option.
59 extraEnvironment = mkOption {
60 type = types.attrsOf types.str;
61 description = lib.mdDoc "Extra environment variables to pass to spark worker.";
64 SPARK_WORKER_CORES = 5;
65 SPARK_WORKER_MEMORY = "2g";
71 description = lib.mdDoc "Spark configuration directory. Spark will use the configuration files (spark-defaults.conf, spark-env.sh, log4j.properties, etc) from this directory.";
72 default = "${cfg.package}/lib/${cfg.package.untarDir}/conf";
73 defaultText = literalExpression ''"''${package}/lib/''${package.untarDir}/conf"'';
77 description = lib.mdDoc "Spark log directory.";
78 default = "/var/log/spark";
82 description = lib.mdDoc "Spark package.";
84 defaultText = literalExpression "pkgs.spark";
85 example = literalExpression ''pkgs.spark.overrideAttrs (super: rec {
90 url = "mirror://apache/spark/"''${pname}-''${version}/''${pname}-''${version}-bin-without-hadoop.tgz";
91 sha256 = "1a9w5k0207fysgpxx6db3a00fs5hdc2ncx99x4ccy2s0v5ndc66g";
97 config = lib.mkIf (cfg.worker.enable || cfg.master.enable) {
98 environment.systemPackages = [ cfg.package ];
101 spark-master = lib.mkIf cfg.master.enable {
102 path = with pkgs; [ procps openssh nettools ];
103 description = "spark master service.";
104 after = [ "network.target" ];
105 wantedBy = [ "multi-user.target" ];
106 restartIfChanged = cfg.master.restartIfChanged;
107 environment = cfg.master.extraEnvironment // {
108 SPARK_MASTER_HOST = cfg.master.bind;
109 SPARK_CONF_DIR = cfg.confDir;
110 SPARK_LOG_DIR = cfg.logDir;
116 WorkingDirectory = "${cfg.package}/lib/${cfg.package.untarDir}";
117 ExecStart = "${cfg.package}/lib/${cfg.package.untarDir}/sbin/start-master.sh";
118 ExecStop = "${cfg.package}/lib/${cfg.package.untarDir}/sbin/stop-master.sh";
124 spark-worker = lib.mkIf cfg.worker.enable {
125 path = with pkgs; [ procps openssh nettools rsync ];
126 description = "spark master service.";
127 after = [ "network.target" ];
128 wantedBy = [ "multi-user.target" ];
129 restartIfChanged = cfg.worker.restartIfChanged;
130 environment = cfg.worker.extraEnvironment // {
131 SPARK_MASTER = cfg.worker.master;
132 SPARK_CONF_DIR = cfg.confDir;
133 SPARK_LOG_DIR = cfg.logDir;
134 SPARK_WORKER_DIR = cfg.worker.workDir;
139 WorkingDirectory = "${cfg.package}/lib/${cfg.package.untarDir}";
140 ExecStart = "${cfg.package}/lib/${cfg.package.untarDir}/sbin/start-worker.sh spark://${cfg.worker.master}";
141 ExecStop = "${cfg.package}/lib/${cfg.package.untarDir}/sbin/stop-worker.sh";
149 "d '${cfg.worker.workDir}' - spark spark - -"
150 "d '${cfg.logDir}' - spark spark - -"
155 description = "spark user.";