-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1245 from midchildan/feat/httpbin-module
httpbin: new module
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
''; | ||
}; | ||
} | ||
|