global(utils): allow changing proxy host with mkSimpleProxy

Changed files
+6 -5
docs
src
global
+2 -1
docs/src/utils/mkSimpleProxy.md
···
# `_utils.mkSimpleProxy`
-
`{port, protocol, location, websockets, extraConfig} -> freeformAttrset`
make a simple reverse proxy
takes a set:
```nix
{
port ? null,
socketPath ? null,
protocol ? "http",
···
# `_utils.mkSimpleProxy`
+
`attrSet -> freeformAttrset`
make a simple reverse proxy
takes a set:
```nix
{
+
host ? "localhost", # proxying servers on the network
port ? null,
socketPath ? null,
protocol ? "http",
+4 -4
global/utils.nix
···
# To override, mkForce {}
locations."= /robots.txt" = mkNginxFile {
-
status = 502;
filename = "robots.txt";
content = ''
# Please stop hammering and/or scraping our services.
···
mkSimpleProxy = {
protocol ? "http",
port ? null,
socketPath ? null,
location ? "/",
···
assert lib.assertMsg (port != null || socketPath != null) "one of port or socketPath must be specified";
# i dislike logic gates
assert lib.assertMsg (!(port != null && socketPath != null)) "only one of port or socketPath may be specified at the same time";
assert lib.assertMsg (port != null -> builtins.isInt port) "port must be an integer if specified";
mkVhost (lib.mkMerge [
extraConfig
···
"${protocol}://"
+ (
if (socketPath == null)
-
then "localhost:${builtins.toString port}"
else "unix:${socketPath}"
);
proxyWebsockets = websockets;
···
mkNginxFile = {
filename ? "index.html",
content,
-
status ? 200,
}:
builtins.addErrorContext "while creating a static nginx file ${filename}" (
let
···
builtins.toString (pkgs.writeTextDir filename content) + "/";
in {
alias = contentDir;
-
tryFiles = "${filename} =${builtins.toString status}";
}
);
···
# To override, mkForce {}
locations."= /robots.txt" = mkNginxFile {
filename = "robots.txt";
content = ''
# Please stop hammering and/or scraping our services.
···
mkSimpleProxy = {
protocol ? "http",
+
host ? "localhost",
port ? null,
socketPath ? null,
location ? "/",
···
assert lib.assertMsg (port != null || socketPath != null) "one of port or socketPath must be specified";
# i dislike logic gates
assert lib.assertMsg (!(port != null && socketPath != null)) "only one of port or socketPath may be specified at the same time";
+
assert lib.assertMsg (socketPath != null -> host == "localhost") "setting host has no effect when socketPath is set";
assert lib.assertMsg (port != null -> builtins.isInt port) "port must be an integer if specified";
mkVhost (lib.mkMerge [
extraConfig
···
"${protocol}://"
+ (
if (socketPath == null)
+
then "${host}:${builtins.toString port}"
else "unix:${socketPath}"
);
proxyWebsockets = websockets;
···
mkNginxFile = {
filename ? "index.html",
content,
}:
builtins.addErrorContext "while creating a static nginx file ${filename}" (
let
···
builtins.toString (pkgs.writeTextDir filename content) + "/";
in {
alias = contentDir;
+
tryFiles = "${filename} =500"; # if it can't find the file something has gone wrong.
}
);