2024-05-24 21:33:37 +00:00
|
|
|
# Serves a binary cache for Nix packages
|
2024-08-02 21:55:48 +00:00
|
|
|
{ config, lib, ... }:
|
2024-05-24 21:33:37 +00:00
|
|
|
|
|
|
|
let
|
2024-06-24 15:38:28 +00:00
|
|
|
cfg = config.aux.system.services.cache;
|
2024-05-24 21:33:37 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
2024-06-24 15:38:28 +00:00
|
|
|
aux.system.services.cache = {
|
2024-05-24 21:33:37 +00: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 15:07:10 +00:00
|
|
|
# Enable cache service
|
2024-05-24 21:33:37 +00:00
|
|
|
services = {
|
|
|
|
nix-serve = {
|
|
|
|
enable = true;
|
2024-05-24 21:42:22 +00:00
|
|
|
secretKeyFile = cfg.secretKeyFile;
|
2024-05-24 21:33:37 +00: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 15:07:10 +00: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 21:33:37 +00:00
|
|
|
};
|
|
|
|
}
|