Skip to content

Commit

Permalink
Merge pull request #1245 from midchildan/feat/httpbin-module
Browse files Browse the repository at this point in the history
httpbin: new module
  • Loading branch information
domenkozar authored May 31, 2024
2 parents fe3b1de + 7eede9f commit b6293aa
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
7 changes: 7 additions & 0 deletions examples/httpbin/.test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -euxo pipefail

for port in 8080 8081; do
wait_for_port "$port"
curl -vf "http://127.0.0.1:$port/headers"
done
10 changes: 10 additions & 0 deletions examples/httpbin/devenv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{ pkgs, ... }:

{
packages = [ pkgs.curl ];

services.httpbin = {
enable = true;
bind = [ "127.0.0.1:8080" "127.0.0.1:8081" ];
};
}
34 changes: 34 additions & 0 deletions src/modules/services/httpbin.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{ pkgs, lib, config, ... }:

let
cfg = config.services.httpbin;

qs = lib.escapeShellArgs;

python = pkgs.python3.withPackages (ps: with ps; [ httpbin gunicorn gevent ]);
binds = lib.concatMap (addr: [ "-b" addr ]) cfg.bind;
in
{
options.services.httpbin = {
enable = lib.mkEnableOption "httpbin";

bind = lib.mkOption {
type = with lib.types; listOf str;
default = [ "127.0.0.1:8080" ];
description = "Addresses for httpbin to listen on.";
};

extraArgs = lib.mkOption {
type = with lib.types; listOf str;
default = [ ];
description = "Gunicorn CLI arguments for httpbin.";
};
};

config = lib.mkIf cfg.enable {
processes.httpbin.exec = ''
exec ${python}/bin/gunicorn httpbin:app -k gevent ${qs binds} ${qs cfg.extraArgs}
'';
};
}

0 comments on commit b6293aa

Please sign in to comment.