1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.mesos.slave;
7
8 mkAttributes =
9 attrs: concatStringsSep ";" (mapAttrsToList
10 (k: v: "${k}:${v}")
11 (filterAttrs (k: v: v != null) attrs));
12 attribsArg = optionalString (cfg.attributes != {})
13 "--attributes=${mkAttributes cfg.attributes}";
14
15 containerizers = [ "mesos" ] ++ (optional cfg.withDocker "docker");
16
17in {
18
19 options.services.mesos = {
20 slave = {
21 enable = mkOption {
22 description = "Whether to enable the Mesos Slave.";
23 default = false;
24 type = types.bool;
25 };
26
27 ip = mkOption {
28 description = "IP address to listen on.";
29 default = "0.0.0.0";
30 type = types.string;
31 };
32
33 port = mkOption {
34 description = "Port to listen on.";
35 default = 5051;
36 type = types.int;
37 };
38
39 master = mkOption {
40 description = ''
41 May be one of:
42 zk://host1:port1,host2:port2,.../path
43 zk://username:password@host1:port1,host2:port2,.../path
44 '';
45 type = types.str;
46 };
47
48 withHadoop = mkOption {
49 description = "Add the HADOOP_HOME to the slave.";
50 default = false;
51 type = types.bool;
52 };
53
54 withDocker = mkOption {
55 description = "Enable the docker containerizer.";
56 default = config.virtualisation.docker.enable;
57 type = types.bool;
58 };
59
60 workDir = mkOption {
61 description = "The Mesos work directory.";
62 default = "/var/lib/mesos/slave";
63 type = types.str;
64 };
65
66 extraCmdLineOptions = mkOption {
67 description = ''
68 Extra command line options for Mesos Slave.
69
70 See https://mesos.apache.org/documentation/latest/configuration/
71 '';
72 default = [ "" ];
73 type = types.listOf types.str;
74 example = [ "--gc_delay=3days" ];
75 };
76
77 logLevel = mkOption {
78 description = ''
79 The logging level used. Possible values:
80 'INFO', 'WARNING', 'ERROR'
81 '';
82 default = "INFO";
83 type = types.str;
84 };
85
86 attributes = mkOption {
87 description = ''
88 Machine attributes for the slave instance.
89
90 Use caution when changing this; you may need to manually reset slave
91 metadata before the slave can re-register.
92 '';
93 default = {};
94 type = types.attrsOf types.str;
95 example = { rack = "aa";
96 host = "aabc123";
97 os = "nixos"; };
98 };
99 };
100
101 };
102
103
104 config = mkIf cfg.enable {
105 systemd.services.mesos-slave = {
106 description = "Mesos Slave";
107 wantedBy = [ "multi-user.target" ];
108 after = [ "network-interfaces.target" ];
109 environment.MESOS_CONTAINERIZERS = concatStringsSep "," containerizers;
110 serviceConfig = {
111 ExecStart = ''
112 ${pkgs.mesos}/bin/mesos-slave \
113 --ip=${cfg.ip} \
114 --port=${toString cfg.port} \
115 --master=${cfg.master} \
116 --work_dir=${cfg.workDir} \
117 --logging_level=${cfg.logLevel} \
118 ${attribsArg} \
119 ${optionalString cfg.withHadoop "--hadoop-home=${pkgs.hadoop}"} \
120 ${optionalString cfg.withDocker "--docker=${pkgs.docker}/libexec/docker/docker"} \
121 ${toString cfg.extraCmdLineOptions}
122 '';
123 PermissionsStartOnly = true;
124 };
125 preStart = ''
126 mkdir -m 0700 -p ${cfg.workDir}
127 '';
128 };
129 };
130
131}