nix-rehash/supervisord.nix

100 lines
2.4 KiB
Nix
Raw Normal View History

{ config, pkgs, ... }:
with pkgs.lib;
let
serviceOpts = { name, config, ...}: {
options = {
command = mkOption {
description = "The command to execute";
};
directory = mkOption {
default = "/";
description = "Current directory when running the command";
};
2013-11-04 19:21:26 +04:00
environment = mkOption {
default = {};
example = {
PATH = "/some/path";
};
};
path = mkOption {
default = [];
description = "Current directory when running the command";
};
stopsignal = mkOption {
default = "TERM";
};
2013-11-08 14:26:23 +04:00
startsecs = mkOption {
default = 1;
example = 0;
};
};
};
services = config.supervisord.services;
in {
options = {
supervisord = {
enable = mkOption {
default = true;
type = types.bool;
};
services = mkOption {
default = {};
type = types.loaOf types.optionSet;
description = ''
Supervisord services to start
'';
options = [ serviceOpts ];
};
tailLogs = mkOption {
default = false;
type = types.bool;
description = ''
Whether or not to tail all logs to standard out.
'';
};
configFile = mkOption {};
};
};
config = mkIf config.supervisord.enable {
supervisord.configFile = pkgs.writeText "supervisord.conf" ''
[supervisord]
[supervisorctl]
serverurl = http://localhost:64125
[inet_http_server]
port = 127.0.0.1:64125
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
${concatMapStrings (name:
let
cfg = getAttr name services;
in
''
[program:${name}]
command=${cfg.command}
environment=${concatStrings
(mapAttrsToList (name: value: "${name}=\"${value}\",") (
cfg.environment // { PATH = concatStringsSep ":"
[("%(ENV_PATH)s") (cfg.path) (maybeAttr "PATH" "" cfg.environment)];
}
)
)}
directory=${cfg.directory}
redirect_stderr=true
2013-11-08 14:26:23 +04:00
startsecs=${toString cfg.startsecs}
stopsignal=${cfg.stopsignal}
stopasgroup=true
''
) (attrNames services)
}
'';
};
2014-02-17 03:31:11 +04:00
}