binary-cache/modules/nginx.nix

37 lines
1.1 KiB
Nix
Raw Normal View History

2024-07-19 10:51:57 +02:00
{ lib, config, ... }:
{
options = {
services.tvix-binary-cache = {
enableNginx = lib.mkEnableOption "nginx reverse proxy for each binary cache";
nginx = {
clientMaxBodySize = lib.mkOption {
type = lib.types.str;
default = "10m";
example = "50G";
};
host = lib.mkOption {
type = lib.types.str;
example = "cache.example.com";
};
};
};
};
config = {
services.nginx = lib.mkIf config.services.tvix-binary-cache.enableNginx {
enable = true;
recommendedProxySettings = true;
virtualHosts.${config.services.tvix-binary-cache.nginx.host} = {
locations = lib.mkMerge (
lib.mapAttrsToList (name: cfg: {
"/${name}".return = "302 /${name}/";
"/${name}/" = {
proxyPass = "http://${toString cfg.narBridgeListenAddress}/";
2024-07-19 10:51:57 +02:00
};
}) config.services.tvix-binary-cache.caches
);
};
inherit (config.services.tvix-binary-cache.nginx) clientMaxBodySize;
};
};
}