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