2014-08-26 18:56:54 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.mesos.slave;
|
2014-12-02 11:10:15 +00:00
|
|
|
|
2014-12-17 22:46:01 +00:00
|
|
|
mkAttributes =
|
|
|
|
attrs: concatStringsSep ";" (mapAttrsToList
|
|
|
|
(k: v: "${k}:${v}")
|
|
|
|
(filterAttrs (k: v: v != null) attrs));
|
|
|
|
attribsArg = optionalString (cfg.attributes != {})
|
|
|
|
"--attributes=${mkAttributes cfg.attributes}";
|
|
|
|
|
2015-04-20 20:54:58 +00:00
|
|
|
containerizers = [ "mesos" ] ++ (optional cfg.withDocker "docker");
|
|
|
|
|
2014-08-26 18:56:54 +00:00
|
|
|
in {
|
|
|
|
|
|
|
|
options.services.mesos = {
|
|
|
|
slave = {
|
|
|
|
enable = mkOption {
|
|
|
|
description = "Whether to enable the Mesos Slave.";
|
|
|
|
default = false;
|
2015-06-15 16:10:26 +00:00
|
|
|
type = types.bool;
|
2014-08-26 18:56:54 +00:00
|
|
|
};
|
|
|
|
|
2015-04-20 20:54:58 +00:00
|
|
|
ip = mkOption {
|
|
|
|
description = "IP address to listen on.";
|
|
|
|
default = "0.0.0.0";
|
|
|
|
type = types.string;
|
|
|
|
};
|
|
|
|
|
2014-08-26 18:56:54 +00:00
|
|
|
port = mkOption {
|
2015-04-20 20:54:58 +00:00
|
|
|
description = "Port to listen on.";
|
2014-08-26 18:56:54 +00:00
|
|
|
default = 5051;
|
|
|
|
type = types.int;
|
|
|
|
};
|
|
|
|
|
|
|
|
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 11:10:15 +00:00
|
|
|
|
2014-08-26 18:56:54 +00:00
|
|
|
withHadoop = mkOption {
|
2014-12-17 22:46:01 +00:00
|
|
|
description = "Add the HADOOP_HOME to the slave.";
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
2014-08-26 18:56:54 +00:00
|
|
|
};
|
2014-12-02 11:10:15 +00:00
|
|
|
|
2015-04-20 20:54:58 +00:00
|
|
|
withDocker = mkOption {
|
|
|
|
description = "Enable the docker containerizer.";
|
|
|
|
default = config.virtualisation.docker.enable;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
2014-08-26 18:56:54 +00:00
|
|
|
workDir = mkOption {
|
|
|
|
description = "The Mesos work directory.";
|
|
|
|
default = "/var/lib/mesos/slave";
|
|
|
|
type = types.str;
|
|
|
|
};
|
2014-12-02 11:10:15 +00:00
|
|
|
|
2014-08-26 18:56:54 +00:00
|
|
|
extraCmdLineOptions = mkOption {
|
|
|
|
description = ''
|
2014-12-17 22:46:01 +00:00
|
|
|
Extra command line options for Mesos Slave.
|
2014-12-02 11:10:15 +00:00
|
|
|
|
2014-12-17 22:46:01 +00:00
|
|
|
See https://mesos.apache.org/documentation/latest/configuration/
|
|
|
|
'';
|
2014-08-26 18:56:54 +00:00
|
|
|
default = [ "" ];
|
2015-06-15 16:18:46 +00:00
|
|
|
type = types.listOf types.str;
|
2014-08-26 18:56:54 +00:00
|
|
|
example = [ "--gc_delay=3days" ];
|
|
|
|
};
|
2014-12-02 11:10:15 +00:00
|
|
|
|
2014-08-26 18:56:54 +00:00
|
|
|
logLevel = mkOption {
|
|
|
|
description = ''
|
|
|
|
The logging level used. Possible values:
|
|
|
|
'INFO', 'WARNING', 'ERROR'
|
|
|
|
'';
|
|
|
|
default = "INFO";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
2014-12-17 22:46:01 +00: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"; };
|
|
|
|
};
|
2014-08-26 18:56:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.mesos-slave = {
|
|
|
|
description = "Mesos Slave";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network-interfaces.target" ];
|
2015-04-20 20:54:58 +00:00
|
|
|
environment.MESOS_CONTAINERIZERS = concatStringsSep "," containerizers;
|
2014-08-26 18:56:54 +00:00
|
|
|
serviceConfig = {
|
2014-12-17 22:46:01 +00:00
|
|
|
ExecStart = ''
|
|
|
|
${pkgs.mesos}/bin/mesos-slave \
|
2015-04-20 20:54:58 +00:00
|
|
|
--ip=${cfg.ip} \
|
2014-12-17 22:46:01 +00:00
|
|
|
--port=${toString cfg.port} \
|
|
|
|
--master=${cfg.master} \
|
|
|
|
--work_dir=${cfg.workDir} \
|
|
|
|
--logging_level=${cfg.logLevel} \
|
2015-04-20 20:54:58 +00:00
|
|
|
${attribsArg} \
|
|
|
|
${optionalString cfg.withHadoop "--hadoop-home=${pkgs.hadoop}"} \
|
|
|
|
${optionalString cfg.withDocker "--docker=${pkgs.docker}/libexec/docker/docker"} \
|
2014-12-17 22:46:01 +00:00
|
|
|
${toString cfg.extraCmdLineOptions}
|
|
|
|
'';
|
|
|
|
PermissionsStartOnly = true;
|
2014-08-26 18:56:54 +00:00
|
|
|
};
|
|
|
|
preStart = ''
|
2014-12-17 22:46:01 +00:00
|
|
|
mkdir -m 0700 -p ${cfg.workDir}
|
2014-08-26 18:56:54 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2014-12-02 11:10:15 +00:00
|
|
|
|
|
|
|
}
|