modified setup.nix so that the proxy functions take cfg

This commit is contained in:
2025-01-22 03:54:23 -06:00
parent d477f15cbc
commit 0152d4a1a8
21 changed files with 30 additions and 58 deletions

View File

@@ -41,30 +41,25 @@ let
default = "${config.my.servers.${name}.hostName}" == config.my.mainServer;
};
};
proxy = locations: {
proxy = cfg: locations: {
inherit locations;
forceSSL = true;
enableACME = true;
http2 = true;
# listenAddresses = [ cfg.ip ];
};
proxyReverse =
host: port:
let
useLocalhost = host == config.networking.hostName;
proxyTarget = if useLocalhost then config.my.localhost else config.my.ips."${host}";
in
proxy { "/".proxyPass = "http://${proxyTarget}:${toString port}/"; };
proxyReverse = cfg: proxy cfg { "/".proxyPass = "http://${cfg.ip}:${toString cfg.port}/"; };
proxyReverseFix =
host: port:
cfg:
let
useLocalhost = host == config.networking.hostName;
useLocalhost = cfg.hostName == config.networking.hostName;
localHeaders = ''
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
'';
in
proxyReverse host port
proxyReverse cfg
// {
extraConfig = ''
${if useLocalhost then localHeaders else ""}