2023-08-19 14:16:19 +02:00
|
|
|
# Binary cache
|
|
|
|
{ config, lib, ... }:
|
2023-04-19 22:23:01 +02:00
|
|
|
let
|
2023-08-19 12:34:22 +02:00
|
|
|
cfg = config.my.services.nix-cache;
|
2023-04-19 22:23:01 +02:00
|
|
|
in
|
|
|
|
{
|
2023-08-19 12:34:22 +02:00
|
|
|
options.my.services.nix-cache = with lib; {
|
|
|
|
enable = mkEnableOption "nix binary cache";
|
2023-04-19 22:23:01 +02:00
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 5000;
|
|
|
|
example = 8080;
|
|
|
|
description = "Internal port for serving cache";
|
|
|
|
};
|
|
|
|
|
|
|
|
secretKeyFile = mkOption {
|
|
|
|
type = types.str;
|
2023-08-19 12:34:22 +02:00
|
|
|
example = "/run/secrets/nix-cache";
|
2023-04-19 22:23:01 +02:00
|
|
|
description = "Secret signing key for the cache";
|
|
|
|
};
|
|
|
|
|
|
|
|
priority = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 50;
|
|
|
|
example = 30;
|
|
|
|
description = ''
|
|
|
|
Which priority to assign to this cache. Lower number is higher priority.
|
|
|
|
The official nixpkgs hydra cache is priority 40.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
2023-08-19 14:16:19 +02:00
|
|
|
services.harmonia = {
|
2023-04-19 22:23:01 +02:00
|
|
|
enable = true;
|
|
|
|
|
2023-08-19 14:16:19 +02:00
|
|
|
settings = {
|
|
|
|
bind = "127.0.0.1:${toString cfg.port}";
|
|
|
|
inherit (cfg) priority;
|
|
|
|
};
|
2023-04-19 22:23:01 +02:00
|
|
|
|
2023-08-19 14:16:19 +02:00
|
|
|
signKeyPath = cfg.secretKeyFile;
|
2023-04-19 22:23:01 +02:00
|
|
|
};
|
|
|
|
|
2023-12-25 19:25:08 +01:00
|
|
|
my.services.nginx.virtualHosts = {
|
|
|
|
cache = {
|
2023-04-19 22:23:01 +02:00
|
|
|
inherit (cfg) port;
|
2023-12-25 19:25:08 +01:00
|
|
|
};
|
|
|
|
};
|
2023-04-19 22:23:01 +02:00
|
|
|
};
|
|
|
|
}
|