Signed-off-by: Harald Hoyer <harald@hoyer.xyz>
This commit is contained in:
Harald Hoyer 2024-11-19 10:31:29 +01:00
parent a3187e163d
commit 900f95169f
83 changed files with 1134 additions and 705 deletions

View file

@ -1,4 +1,8 @@
{ lib, inputs, snowfall-inputs }:
{
lib,
inputs,
snowfall-inputs,
}:
let
inherit (inputs.nixpkgs.lib) assertMsg last;
@ -9,14 +13,17 @@ in
# Type: String -> Attrs
# Usage: get-address-parts "bismuth:3000"
# result: { host = "bismuth"; port = "3000"; }
get-address-parts = address:
get-address-parts =
address:
let
address-parts = builtins.split ":" address;
ip = builtins.head address-parts;
host = if ip == "" then "127.0.0.1" else ip;
port = if builtins.length address-parts != 3 then "" else last address-parts;
in
{ inherit host port; };
{
inherit host port;
};
## Create proxy configuration for NGINX virtual hosts.
##
@ -33,22 +40,23 @@ in
##
#@ { port: Int ? null, host: String ? "127.0.0.1", proxy-web-sockets: Bool ? false, extra-config: Attrs ? { } } -> Attrs
create-proxy =
{ port ? null
, host ? "127.0.0.1"
, proxy-web-sockets ? false
, extra-config ? { }
{
port ? null,
host ? "127.0.0.1",
proxy-web-sockets ? false,
extra-config ? { },
}:
assert assertMsg (port != "" && port != null) "port cannot be empty";
assert assertMsg (host != "") "host cannot be empty";
extra-config // {
locations = (extra-config.locations or { }) // {
"/" = (extra-config.locations."/" or { }) // {
proxyPass =
"http://${host}${if port != null then ":${builtins.toString port}" else ""}";
assert assertMsg (port != "" && port != null) "port cannot be empty";
assert assertMsg (host != "") "host cannot be empty";
extra-config
// {
locations = (extra-config.locations or { }) // {
"/" = (extra-config.locations."/" or { }) // {
proxyPass = "http://${host}${if port != null then ":${builtins.toString port}" else ""}";
proxyWebsockets = proxy-web-sockets;
};
proxyWebsockets = proxy-web-sockets;
};
};
};
};
}