2024-12-02 02:01:53 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
2024-12-06 16:46:10 +00:00
|
|
|
namespace,
|
2024-12-02 02:01:53 +00:00
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2024-12-06 16:46:10 +00:00
|
|
|
cfg = config.${namespace}.services.binary-cache;
|
2024-12-02 02:01:53 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
2024-12-06 16:46:10 +00:00
|
|
|
${namespace}.services.binary-cache = {
|
2024-12-02 02:01:53 +00:00
|
|
|
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}" = {
|
2024-12-06 16:16:58 +00:00
|
|
|
useACMEHost = lib.Sapana.getDomainFromURI cfg.url;
|
2024-12-02 02:01:53 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
}
|