1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7let
8 cfg = config.services.beanstalkd;
9 pkg = pkgs.beanstalkd;
10in
11
12{
13 # interface
14
15 options = {
16 services.beanstalkd = {
17 enable = lib.mkEnableOption "the Beanstalk work queue";
18
19 listen = {
20 port = lib.mkOption {
21 type = lib.types.port;
22 description = "TCP port that will be used to accept client connections.";
23 default = 11300;
24 };
25
26 address = lib.mkOption {
27 type = lib.types.str;
28 description = "IP address to listen on.";
29 default = "127.0.0.1";
30 example = "0.0.0.0";
31 };
32 };
33
34 openFirewall = lib.mkOption {
35 type = lib.types.bool;
36 default = false;
37 description = "Whether to open ports in the firewall for the server.";
38 };
39 };
40 };
41
42 # implementation
43
44 config = lib.mkIf cfg.enable {
45
46 networking.firewall = lib.mkIf cfg.openFirewall {
47 allowedTCPPorts = [ cfg.listen.port ];
48 };
49
50 environment.systemPackages = [ pkg ];
51
52 systemd.services.beanstalkd = {
53 description = "Beanstalk Work Queue";
54 after = [ "network.target" ];
55 wantedBy = [ "multi-user.target" ];
56 serviceConfig = {
57 DynamicUser = true;
58 Restart = "always";
59 ExecStart = "${pkg}/bin/beanstalkd -l ${cfg.listen.address} -p ${toString cfg.listen.port} -b $STATE_DIRECTORY";
60 StateDirectory = "beanstalkd";
61 };
62 };
63
64 };
65}