self-hosting/modules/binary-cache.nix

38 lines
922 B
Nix
Raw Permalink Normal View History

{ config, lib, ... }:
2024-03-26 23:37:53 +01:00
let cfg = config.custom.services.binary-cache;
in {
options.custom.services.binary-cache = {
2022-09-15 03:40:09 +02:00
2024-03-26 23:37:53 +01:00
enable = lib.mkEnableOption "binary-cache";
2024-03-26 23:37:53 +01:00
secretKeyFile = lib.mkOption { type = lib.types.path; };
2022-09-15 03:40:09 +02:00
};
2024-03-26 23:37:53 +01:00
config = lib.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 = ''
2024-03-26 23:37:53 +01:00
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
};
};
};
}