2024-05-24 17:33:37 -04:00
|
|
|
# Serves a binary cache for Nix packages
|
2024-08-02 17:55:48 -04:00
|
|
|
{ config, lib, ... }:
|
2024-05-24 17:33:37 -04:00
|
|
|
|
|
|
|
let
|
2024-06-24 11:38:28 -04:00
|
|
|
cfg = config.aux.system.services.cache;
|
2024-05-24 17:33:37 -04:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
2024-06-24 11:38:28 -04:00
|
|
|
aux.system.services.cache = {
|
2024-05-24 17:33:37 -04:00
|
|
|
enable = lib.mkEnableOption (lib.mdDoc "Enables binary cache hosting.");
|
|
|
|
secretKeyFile = lib.mkOption {
|
|
|
|
default = "/var/cache-priv-key.pem";
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "Where the signing key lives.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
2024-05-25 11:07:10 -04:00
|
|
|
# Enable cache service
|
2024-05-24 17:33:37 -04:00
|
|
|
services = {
|
|
|
|
nix-serve = {
|
|
|
|
enable = true;
|
2024-05-24 17:42:22 -04:00
|
|
|
secretKeyFile = cfg.secretKeyFile;
|
2024-05-24 17:33:37 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
nginx.virtualHosts."${config.secrets.services.cache.url}" = {
|
|
|
|
useACMEHost = config.secrets.networking.primaryDomain;
|
|
|
|
forceSSL = true;
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://${config.services.nix-serve.bindAddress}:${toString config.services.nix-serve.port}";
|
|
|
|
extraConfig = "proxy_ssl_server_name on;";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-05-25 11:07:10 -04:00
|
|
|
|
|
|
|
nix.settings = {
|
|
|
|
extra-substituters = [ "ssh://${config.secrets.services.cache.url}" ];
|
|
|
|
trusted-public-keys = [
|
|
|
|
"${config.secrets.services.cache.url}:mTYvveYNhoXttGOxJj2uP0MQ/ZPJce5hY+xSvOxswls=%"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
# Run nightly builds for certain targets
|
|
|
|
systemd.timers."nix-distributed-build-timer" = {
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
timerConfig = {
|
|
|
|
OnCalendar = "daily";
|
|
|
|
Persistent = "true";
|
|
|
|
Unit = "nix-distributed-build.service";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services."nix-distributed-build" = {
|
|
|
|
# Add target names below as a new line
|
|
|
|
script = ''
|
|
|
|
set -eu
|
|
|
|
nh os build --update --hostname Khanda
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
User = config.users.users.aires.name;
|
|
|
|
};
|
|
|
|
};
|
2024-05-24 17:33:37 -04:00
|
|
|
};
|
|
|
|
}
|