| 
									
										
										
										
											2014-08-26 20:56:54 +02:00
										 |  |  | { config, lib, pkgs, ... }: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | with lib; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let | 
					
						
							|  |  |  |   cfg = config.services.mesos.slave; | 
					
						
							| 
									
										
										
										
											2014-12-02 12:10:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-17 14:46:01 -08:00
										 |  |  |   mkAttributes = | 
					
						
							|  |  |  |     attrs: concatStringsSep ";" (mapAttrsToList | 
					
						
							|  |  |  |                                    (k: v: "${k}:${v}") | 
					
						
							|  |  |  |                                    (filterAttrs (k: v: v != null) attrs)); | 
					
						
							|  |  |  |   attribsArg = optionalString (cfg.attributes != {}) | 
					
						
							|  |  |  |                               "--attributes=${mkAttributes cfg.attributes}"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-28 00:19:51 -05:00
										 |  |  |   containerizersArg = concatStringsSep "," ( | 
					
						
							|  |  |  |     lib.unique ( | 
					
						
							|  |  |  |       cfg.containerizers ++ (optional cfg.withDocker "docker") | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   imageProvidersArg = concatStringsSep "," ( | 
					
						
							|  |  |  |     lib.unique ( | 
					
						
							|  |  |  |       cfg.imageProviders ++ (optional cfg.withDocker "docker") | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   isolationArg = concatStringsSep "," ( | 
					
						
							|  |  |  |     lib.unique ( | 
					
						
							|  |  |  |       cfg.isolation ++ (optionals cfg.withDocker [ "filesystem/linux" "docker/runtime"]) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2015-04-20 21:54:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-26 20:56:54 +02:00
										 |  |  | in { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   options.services.mesos = { | 
					
						
							|  |  |  |     slave = { | 
					
						
							|  |  |  |       enable = mkOption { | 
					
						
							|  |  |  |         description = "Whether to enable the Mesos Slave."; | 
					
						
							|  |  |  |         default = false; | 
					
						
							| 
									
										
										
										
											2015-06-15 18:10:26 +02:00
										 |  |  |         type = types.bool; | 
					
						
							| 
									
										
										
										
											2014-08-26 20:56:54 +02:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-20 21:54:58 +01:00
										 |  |  |       ip = mkOption { | 
					
						
							|  |  |  |         description = "IP address to listen on."; | 
					
						
							|  |  |  |         default = "0.0.0.0"; | 
					
						
							| 
									
										
										
										
											2016-12-28 00:19:51 -05:00
										 |  |  |         type = types.str; | 
					
						
							| 
									
										
										
										
											2015-04-20 21:54:58 +01:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-26 20:56:54 +02:00
										 |  |  |       port = mkOption { | 
					
						
							| 
									
										
										
										
											2015-04-20 21:54:58 +01:00
										 |  |  |         description = "Port to listen on."; | 
					
						
							| 
									
										
										
										
											2014-08-26 20:56:54 +02:00
										 |  |  |         default = 5051; | 
					
						
							|  |  |  |         type = types.int; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-28 00:19:51 -05:00
										 |  |  |       advertiseIp = mkOption { | 
					
						
							|  |  |  |         description = "IP address advertised to reach this agent."; | 
					
						
							|  |  |  |         default = null; | 
					
						
							|  |  |  |         type = types.nullOr types.str; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       advertisePort = mkOption { | 
					
						
							|  |  |  |         description = "Port advertised to reach this agent."; | 
					
						
							|  |  |  |         default = null; | 
					
						
							|  |  |  |         type = types.nullOr types.int; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       containerizers = mkOption { | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           List of containerizer implementations to compose in order to provide | 
					
						
							|  |  |  |           containerization. Available options are mesos and docker. | 
					
						
							|  |  |  |           The order the containerizers are specified is the order they are tried. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |         default = [ "mesos" ]; | 
					
						
							|  |  |  |         type = types.listOf types.str; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       imageProviders = mkOption { | 
					
						
							|  |  |  |         description = "List of supported image providers, e.g., APPC,DOCKER."; | 
					
						
							|  |  |  |         default = [ ]; | 
					
						
							|  |  |  |         type = types.listOf types.str; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       imageProvisionerBackend = mkOption { | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           Strategy for provisioning container rootfs from images, | 
					
						
							|  |  |  |           e.g., aufs, bind, copy, overlay. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |         default = "copy"; | 
					
						
							|  |  |  |         type = types.str; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       isolation = mkOption { | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           Isolation mechanisms to use, e.g., posix/cpu,posix/mem, or | 
					
						
							|  |  |  |           cgroups/cpu,cgroups/mem, or network/port_mapping, or `gpu/nvidia` for nvidia | 
					
						
							|  |  |  |           specific gpu isolation. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |         default = [ "posix/cpu" "posix/mem" ]; | 
					
						
							|  |  |  |         type = types.listOf types.str; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-26 20:56:54 +02:00
										 |  |  |       master = mkOption { | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           May be one of: | 
					
						
							|  |  |  |             zk://host1:port1,host2:port2,.../path | 
					
						
							|  |  |  |             zk://username:password@host1:port1,host2:port2,.../path | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |         type = types.str; | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2014-12-02 12:10:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-26 20:56:54 +02:00
										 |  |  |       withHadoop = mkOption { | 
					
						
							| 
									
										
										
										
											2014-12-17 14:46:01 -08:00
										 |  |  |         description = "Add the HADOOP_HOME to the slave."; | 
					
						
							|  |  |  |         default = false; | 
					
						
							|  |  |  |         type = types.bool; | 
					
						
							| 
									
										
										
										
											2014-08-26 20:56:54 +02:00
										 |  |  |       }; | 
					
						
							| 
									
										
										
										
											2014-12-02 12:10:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-20 21:54:58 +01:00
										 |  |  |       withDocker = mkOption { | 
					
						
							|  |  |  |         description = "Enable the docker containerizer."; | 
					
						
							|  |  |  |         default = config.virtualisation.docker.enable; | 
					
						
							|  |  |  |         type = types.bool; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-28 00:19:51 -05:00
										 |  |  |       dockerRegistry = mkOption { | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           The default url for pulling Docker images. | 
					
						
							|  |  |  |           It could either be a Docker registry server url, | 
					
						
							|  |  |  |           or a local path in which Docker image archives are stored. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |         default = null; | 
					
						
							|  |  |  |         type = types.nullOr (types.either types.str types.path); | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-26 20:56:54 +02:00
										 |  |  |       workDir = mkOption { | 
					
						
							|  |  |  |         description = "The Mesos work directory."; | 
					
						
							|  |  |  |         default = "/var/lib/mesos/slave"; | 
					
						
							|  |  |  |         type = types.str; | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2014-12-02 12:10:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-26 20:56:54 +02:00
										 |  |  |       extraCmdLineOptions = mkOption { | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							| 
									
										
										
										
											2014-12-17 14:46:01 -08:00
										 |  |  |           Extra command line options for Mesos Slave. | 
					
						
							| 
									
										
										
										
											2014-12-02 12:10:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-17 14:46:01 -08:00
										 |  |  |           See https://mesos.apache.org/documentation/latest/configuration/ | 
					
						
							|  |  |  |         '';
 | 
					
						
							| 
									
										
										
										
											2014-08-26 20:56:54 +02:00
										 |  |  |         default = [ "" ]; | 
					
						
							| 
									
										
										
										
											2015-06-15 18:18:46 +02:00
										 |  |  |         type = types.listOf types.str; | 
					
						
							| 
									
										
										
										
											2014-08-26 20:56:54 +02:00
										 |  |  |         example = [ "--gc_delay=3days" ]; | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2014-12-02 12:10:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-26 20:56:54 +02:00
										 |  |  |       logLevel = mkOption { | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           The logging level used. Possible values: | 
					
						
							|  |  |  |             'INFO', 'WARNING', 'ERROR' | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |         default = "INFO"; | 
					
						
							|  |  |  |         type = types.str; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-17 14:46:01 -08:00
										 |  |  |       attributes = mkOption { | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           Machine attributes for the slave instance. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           Use caution when changing this; you may need to manually reset slave | 
					
						
							|  |  |  |           metadata before the slave can re-register. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |         default = {}; | 
					
						
							|  |  |  |         type = types.attrsOf types.str; | 
					
						
							|  |  |  |         example = { rack = "aa"; | 
					
						
							|  |  |  |                     host = "aabc123"; | 
					
						
							|  |  |  |                     os = "nixos"; }; | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2016-12-28 00:19:51 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |       executorEnvironmentVariables = mkOption { | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           The environment variables that should be passed to the executor, and thus subsequently task(s). | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |         default = { | 
					
						
							|  |  |  |           PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         type = types.attrsOf types.str; | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2014-08-26 20:56:54 +02:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   config = mkIf cfg.enable { | 
					
						
							|  |  |  |     systemd.services.mesos-slave = { | 
					
						
							|  |  |  |       description = "Mesos Slave"; | 
					
						
							|  |  |  |       wantedBy = [ "multi-user.target" ]; | 
					
						
							| 
									
										
										
										
											2016-09-10 20:12:23 +02:00
										 |  |  |       after = [ "network.target" ]; | 
					
						
							| 
									
										
										
										
											2016-12-28 00:19:51 -05:00
										 |  |  |       path = [ pkgs.stdenv.shellPackage ]; | 
					
						
							| 
									
										
										
										
											2014-08-26 20:56:54 +02:00
										 |  |  |       serviceConfig = { | 
					
						
							| 
									
										
										
										
											2014-12-17 14:46:01 -08:00
										 |  |  |         ExecStart = ''
 | 
					
						
							|  |  |  |           ${pkgs.mesos}/bin/mesos-slave \ | 
					
						
							| 
									
										
										
										
											2016-12-28 00:19:51 -05:00
										 |  |  |             --containerizers=${containerizersArg} \ | 
					
						
							|  |  |  |             --image_providers=${imageProvidersArg} \ | 
					
						
							|  |  |  |             --image_provisioner_backend=${cfg.imageProvisionerBackend} \ | 
					
						
							|  |  |  |             --isolation=${isolationArg} \ | 
					
						
							| 
									
										
										
										
											2015-04-20 21:54:58 +01:00
										 |  |  |             --ip=${cfg.ip} \ | 
					
						
							| 
									
										
										
										
											2014-12-17 14:46:01 -08:00
										 |  |  |             --port=${toString cfg.port} \ | 
					
						
							| 
									
										
										
										
											2016-12-28 00:19:51 -05:00
										 |  |  |             ${optionalString (cfg.advertiseIp != null) "--advertise_ip=${cfg.advertiseIp}"} \ | 
					
						
							|  |  |  |             ${optionalString (cfg.advertisePort  != null) "--advertise_port=${toString cfg.advertisePort}"} \ | 
					
						
							| 
									
										
										
										
											2014-12-17 14:46:01 -08:00
										 |  |  |             --master=${cfg.master} \ | 
					
						
							|  |  |  |             --work_dir=${cfg.workDir} \ | 
					
						
							|  |  |  |             --logging_level=${cfg.logLevel} \ | 
					
						
							| 
									
										
										
										
											2015-04-20 21:54:58 +01:00
										 |  |  |             ${attribsArg} \ | 
					
						
							|  |  |  |             ${optionalString cfg.withHadoop "--hadoop-home=${pkgs.hadoop}"} \ | 
					
						
							|  |  |  |             ${optionalString cfg.withDocker "--docker=${pkgs.docker}/libexec/docker/docker"} \ | 
					
						
							| 
									
										
										
										
											2016-12-28 00:19:51 -05:00
										 |  |  |             ${optionalString (cfg.dockerRegistry != null) "--docker_registry=${cfg.dockerRegistry}"} \ | 
					
						
							|  |  |  |             --executor_environment_variables=${lib.escapeShellArg (builtins.toJSON cfg.executorEnvironmentVariables)} \ | 
					
						
							| 
									
										
										
										
											2014-12-17 14:46:01 -08:00
										 |  |  |             ${toString cfg.extraCmdLineOptions} | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |         PermissionsStartOnly = true; | 
					
						
							| 
									
										
										
										
											2014-08-26 20:56:54 +02:00
										 |  |  |       }; | 
					
						
							|  |  |  |       preStart = ''
 | 
					
						
							| 
									
										
										
										
											2014-12-17 14:46:01 -08:00
										 |  |  |         mkdir -m 0700 -p ${cfg.workDir} | 
					
						
							| 
									
										
										
										
											2014-08-26 20:56:54 +02:00
										 |  |  |       '';
 | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2014-12-02 12:10:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |