modified setup.nix so that the proxy functions take cfg

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

View File

@ -31,7 +31,7 @@ in
};
};
nginx.virtualHosts."cache.rotehaare.art" = lib.mkIf cfg.enableProxy (
setup.proxyReverseFix cfg.hostName cfg.port // { }
setup.proxyReverseFix cfg // { }
);
};
};

View File

@ -6,15 +6,16 @@ in
{
options.my.servers.audiobookshelf = setup.mkOptions "audiobookshelf" "audiobooks" 5687;
config = {
my.servers.audiobookshelf.ip = "127.0.0.3";
services = {
audiobookshelf = lib.mkIf cfg.enable {
inherit (cfg) port;
enable = true;
host = cfg.ip;
group = "piracy";
openFirewall = true;
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
setup.proxy {
setup.proxy cfg {
"/" = {
proxyPass = cfg.local;
extraConfig = ''

View File

@ -12,9 +12,7 @@ in
enable = true;
group = "piracy";
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
setup.proxyReverse cfg.hostName cfg.port // { }
);
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (setup.proxyReverse cfg // { });
};
};
}

View File

@ -47,8 +47,8 @@ in
};
services.nginx = {
virtualHosts = lib.mkIf (cfg.enableProxy || cfgS.enableProxy) {
"${cfg.host}" = setup.proxyReverse cfg.hostName cfg.port // { };
"${cfgS.host}" = setup.proxyReverse cfgS.hostName cfgS.port // { };
"${cfg.host}" = setup.proxyReverse cfg // { };
"${cfgS.host}" = setup.proxyReverse cfgS // { };
};
};
};

View File

@ -22,9 +22,7 @@ in
|> builtins.filter (file: builtins.match ".*\\.nix" file != null)
|> map (file: import ./homepage/bookmarks/${file});
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
setup.proxyReverse cfg.hostName cfg.port // { }
);
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (setup.proxyReverse cfg // { });
};
};
}

View File

@ -24,9 +24,7 @@ in
enable = true;
tokenKeyFile = config.sops.secrets.kavita-token.path;
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
setup.proxyReverse cfg.hostName cfg.port // { }
);
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (setup.proxyReverse cfg // { });
};
};
}

View File

@ -30,7 +30,7 @@ in
];
};
services.nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
setup.proxyReverseFix cfg.hostName cfg.port // { }
setup.proxyReverseFix cfg // { }
);
};
}

View File

@ -23,7 +23,7 @@ in
volumes = [ "${config.my.containerData}/maloja:/mljdata" ];
};
services.nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
setup.proxyReverse cfg.hostName cfg.port // { }
setup.proxyReverse cfg // { }
);
};
}

View File

@ -27,9 +27,7 @@ in
};
credentialsFile = config.sops.secrets.mealie.path;
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
setup.proxyReverse cfg.hostName cfg.port // { }
);
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (setup.proxyReverse cfg // { });
};
};
}

View File

@ -22,7 +22,7 @@ in
};
};
services.nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
setup.proxyReverse cfg.hostName cfg.port // { }
setup.proxyReverse cfg // { }
);
};
}

View File

@ -20,9 +20,7 @@ in
MICROBIN_ENCRYPTION_SERVER_SIDE = true;
};
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
setup.proxyReverse cfg.hostName cfg.port // { }
);
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (setup.proxyReverse cfg // { });
};
};
}

View File

@ -24,7 +24,7 @@ in
volumes = [ "${config.my.containerData}/multi-scrobbler:/config" ];
};
services.nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
setup.proxyReverse cfg.hostName cfg.port // { }
setup.proxyReverse cfg // { }
);
};
}

View File

@ -20,9 +20,7 @@ in
inherit (cfg) port;
secretKeyFile = config.sops.secrets."private_cache_keys/miniserver".path;
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
setup.proxyReverse cfg.hostName cfg.port // { }
);
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (setup.proxyReverse cfg // { });
};
};
}

View File

@ -12,9 +12,7 @@ in
port = cfg.port;
openFirewall = (!cfg.isLocal);
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
setup.proxyReverseFix cfg.hostName cfg.port // { }
);
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (setup.proxyReverseFix cfg // { });
};
};
}

View File

@ -23,9 +23,7 @@ in
package = pkgs.nur.repos.xddxdd.flaresolverr-21hsmw;
openFirewall = true;
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
setup.proxyReverseFix cfg.hostName cfg.port // { }
);
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (setup.proxyReverseFix cfg // { });
};
};
}

View File

@ -12,9 +12,7 @@ in
enable = true;
group = "piracy";
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
setup.proxyReverseFix cfg.hostName cfg.port // { }
);
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (setup.proxyReverseFix cfg // { });
};
};
}

View File

@ -20,7 +20,7 @@ in
volumes = [ "${config.my.postgresSocket}:${config.my.postgresSocket}" ];
};
services.nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
setup.proxyReverse cfg.hostName cfg.port // { }
setup.proxyReverse cfg // { }
);
};
}

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 ""}

View File

@ -10,14 +10,12 @@ in
sops.secrets = lib.mkIf cfg.enable { shiori.sopsFile = ../../secrets/env.yaml; };
services = {
shiori = lib.mkIf cfg.enable {
enable = true;
inherit (cfg) port;
enable = true;
environmentFile = config.sops.secrets.shiori.path;
databaseUrl = "postgres:///shiori?host=${config.my.postgresSocket}";
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
setup.proxyReverse cfg.hostName cfg.port // { }
);
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (setup.proxyReverse cfg // { });
};
};
}

View File

@ -12,9 +12,7 @@ in
group = "piracy";
openFirewall = (!cfg.isLocal);
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
setup.proxyReverseFix cfg.hostName cfg.port // { }
);
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (setup.proxyReverseFix cfg // { });
};
};
}

View File

@ -31,9 +31,7 @@ in
LOG_LEVEL = "warn";
};
};
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (
setup.proxyReverse cfg.hostName cfg.port // { }
);
nginx.virtualHosts."${cfg.host}" = lib.mkIf cfg.enableProxy (setup.proxyReverse cfg // { });
};
};
}