diff --git a/nixos/doc/manual/release-notes/rl-1903.xml b/nixos/doc/manual/release-notes/rl-1903.xml index c32c0fc14cb8..1b99724c6bc7 100644 --- a/nixos/doc/manual/release-notes/rl-1903.xml +++ b/nixos/doc/manual/release-notes/rl-1903.xml @@ -91,6 +91,11 @@ in nixos/modules/virtualisation/google-compute-config.nix. + + + ./services/misc/beanstalkd.nix + + diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 7af6e117c517..75217581a944 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -361,6 +361,7 @@ ./services/misc/apache-kafka.nix ./services/misc/autofs.nix ./services/misc/autorandr.nix + ./services/misc/beanstalkd.nix ./services/misc/bees.nix ./services/misc/bepasty.nix ./services/misc/canto-daemon.nix diff --git a/nixos/modules/services/misc/beanstalkd.nix b/nixos/modules/services/misc/beanstalkd.nix new file mode 100644 index 000000000000..8a3e0ab1949a --- /dev/null +++ b/nixos/modules/services/misc/beanstalkd.nix @@ -0,0 +1,52 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.beanstalkd; + pkg = pkgs.beanstalkd; +in + +{ + # interface + + options = { + services.beanstalkd = { + enable = mkEnableOption "Enable the Beanstalk work queue."; + + listen = { + port = mkOption { + type = types.int; + description = "TCP port that will be used to accept client connections."; + default = 11300; + }; + + address = mkOption { + type = types.str; + description = "IP address to listen on."; + default = "127.0.0.1"; + example = "0.0.0.0"; + }; + }; + }; + }; + + # implementation + + config = mkIf cfg.enable { + + environment.systemPackages = [ pkg ]; + + systemd.services.beanstalkd = { + description = "Beanstalk Work Queue"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + DynamicUser = true; + Restart = "always"; + ExecStart = "${pkg}/bin/beanstalkd -l ${cfg.listen.address} -p ${toString cfg.listen.port}"; + }; + }; + + }; +} diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 3d8fea95a501..65227857a38e 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -25,6 +25,7 @@ in atd = handleTest ./atd.nix {}; avahi = handleTest ./avahi.nix {}; bcachefs = handleTestOn ["x86_64-linux"] ./bcachefs.nix {}; # linux-4.18.2018.10.12 is unsupported on aarch64 + beanstalkd = handleTest ./beanstalkd.nix {}; beegfs = handleTestOn ["x86_64-linux"] ./beegfs.nix {}; # beegfs is unsupported on aarch64 bind = handleTest ./bind.nix {}; bittorrent = handleTest ./bittorrent.nix {}; diff --git a/nixos/tests/beanstalkd.nix b/nixos/tests/beanstalkd.nix new file mode 100644 index 000000000000..9b7ac111a57b --- /dev/null +++ b/nixos/tests/beanstalkd.nix @@ -0,0 +1,43 @@ +import ./make-test.nix ({ pkgs, lib, ... }: + +let + produce = pkgs.writeScript "produce.py" '' + #!${pkgs.python2.withPackages (p: [p.beanstalkc])}/bin/python + import beanstalkc + + queue = beanstalkc.Connection(host='localhost', port=11300, parse_yaml=False); + queue.put('this is a job') + queue.put('this is another job') + ''; + + consume = pkgs.writeScript "consume.py" '' + #!${pkgs.python2.withPackages (p: [p.beanstalkc])}/bin/python + import beanstalkc + + queue = beanstalkc.Connection(host='localhost', port=11300, parse_yaml=False); + + job = queue.reserve(timeout=0) + print job.body + job.delete() + ''; + +in +{ + name = "beanstalkd"; + meta.maintainers = [ lib.maintainers.aanderse ]; + + machine = + { ... }: + { services.beanstalkd.enable = true; + }; + + testScript = '' + startAll; + + $machine->waitForUnit('beanstalkd.service'); + + $machine->succeed("${produce}"); + $machine->succeed("${consume}") eq "this is a job\n" or die; + $machine->succeed("${consume}") eq "this is another job\n" or die; + ''; +})