self-hosting/modules/binary-cache.nix

42 lines
901 B
Nix
Raw Normal View History

{ config, lib, ... }:
with lib;
let
cfg = config.custom.services.binary-cache;
in
2022-09-15 03:40:09 +02:00
{
options.custom.services.binary-cache = {
2022-09-15 03:40:09 +02:00
enable = mkEnableOption "binary-cache";
secretKeyFile = mkOption {
type = types.path;
2022-09-15 03:40:09 +02:00
};
};
config = mkIf cfg.enable {
services.nix-serve = {
enable = true;
port = 1500;
secretKeyFile = config.sops.secrets.nixCacheKey.path;
};
2022-09-15 03:40:09 +02:00
services.nginx = {
virtualHosts = {
"cache.${config.networking.domain}" = {
2022-09-15 03:40:09 +02:00
enableACME = true;
forceSSL = true;
2022-09-15 03:40:09 +02:00
locations."/".extraConfig = ''
proxy_pass http://localhost:${toString config.services.nix-serve.port};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
'';
};
2022-09-15 03:40:09 +02:00
};
};
};
}