2024-12-02 02:01:53 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.aux.system.services.binary-cache;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
aux.system.services.binary-cache = {
|
|
|
|
enable = lib.mkEnableOption "Enable a binary cache hosting service.";
|
|
|
|
secretKeyFile = lib.mkOption {
|
|
|
|
default = "/var/lib/nix-binary-cache/privkey.pem";
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "Where to find the binary cache's private key.";
|
|
|
|
};
|
|
|
|
url = lib.mkOption {
|
|
|
|
default = "";
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "The complete URL where the cache is hosted.";
|
|
|
|
example = "https://cache.example.com";
|
|
|
|
};
|
2024-12-02 16:26:29 +00:00
|
|
|
auth = {
|
|
|
|
password = lib.mkOption {
|
|
|
|
default = "";
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "The password to use for basic authentication for the cache.";
|
|
|
|
example = "MySuperSecurePassword123";
|
|
|
|
};
|
|
|
|
user = lib.mkOption {
|
|
|
|
default = "cache-user";
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "The username to use for basic auth.";
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
2024-12-02 02:01:53 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
services = {
|
|
|
|
nix-serve = {
|
|
|
|
enable = true;
|
|
|
|
secretKeyFile = cfg.secretKeyFile;
|
|
|
|
bindAddress = "127.0.0.1";
|
|
|
|
};
|
|
|
|
|
|
|
|
nginx.virtualHosts."${cfg.url}" = {
|
|
|
|
useACMEHost = pkgs.util.getDomainFromURL cfg.url;
|
|
|
|
forceSSL = true;
|
2024-12-02 16:26:29 +00:00
|
|
|
basicAuth = {
|
|
|
|
"${cfg.auth.user}" = cfg.auth.password;
|
|
|
|
};
|
2024-12-02 02:01:53 +00:00
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://${config.services.nix-serve.bindAddress}:${toString config.services.nix-serve.port}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-12-02 16:26:29 +00:00
|
|
|
|
|
|
|
systemd.services.nginx.wants = [ config.systemd.services.nix-serve.name ];
|
2024-12-02 02:01:53 +00:00
|
|
|
};
|
|
|
|
}
|