2022-09-16 01:29:46 +02:00
|
|
|
{ config, lib, ... }:
|
2024-03-26 23:37:53 +01:00
|
|
|
let cfg = config.custom.services.binary-cache;
|
|
|
|
|
in {
|
2022-09-16 01:29:46 +02:00
|
|
|
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";
|
2022-09-16 01:29:46 +02:00
|
|
|
|
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 {
|
2022-09-16 01:29:46 +02:00
|
|
|
services.nix-serve = {
|
|
|
|
|
enable = true;
|
|
|
|
|
port = 1500;
|
|
|
|
|
secretKeyFile = config.sops.secrets.nixCacheKey.path;
|
|
|
|
|
};
|
2022-09-15 03:40:09 +02:00
|
|
|
|
2022-09-16 01:29:46 +02:00
|
|
|
services.nginx = {
|
|
|
|
|
virtualHosts = {
|
|
|
|
|
"cache.${config.networking.domain}" = {
|
2022-09-15 03:40:09 +02:00
|
|
|
|
2022-09-16 01:29:46 +02:00
|
|
|
enableACME = true;
|
|
|
|
|
forceSSL = true;
|
2022-09-15 03:40:09 +02:00
|
|
|
|
2022-09-16 01:29:46 +02:00
|
|
|
locations."/".extraConfig = ''
|
2024-03-26 23:37:53 +01:00
|
|
|
proxy_pass http://localhost:${
|
|
|
|
|
toString config.services.nix-serve.port
|
|
|
|
|
};
|
2022-09-16 01:29:46 +02:00
|
|
|
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
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}
|