2024-07-09 22:43:03 +00:00
|
|
|
{ nodes, config, lib, pkgs, ... }:
|
2024-06-24 14:45:59 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.bagel.services.hydra;
|
2024-07-09 22:43:03 +00:00
|
|
|
ssh-keys = import ../../common/ssh-keys.nix;
|
2024-06-24 14:45:59 +00:00
|
|
|
|
|
|
|
narCacheDir = "/var/cache/hydra/nar-cache";
|
|
|
|
port = 3000;
|
|
|
|
|
|
|
|
mkCacheSettings = settings: builtins.concatStringsSep "&" (
|
|
|
|
lib.mapAttrsToList (k: v: "${k}=${v}") settings
|
2024-07-09 22:43:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
mkBaremetalBuilder = { nrCores, publicHostKey, host, speedFactor ? 1, user ? "builder", supportedSystems ? [ "i686-linux" "x86_64-linux" ], supportedFeatures ? [ "big-parallel" "kvm" "nixos-test" ] }:
|
|
|
|
"ssh://${user}@${host} ${lib.concatStringsSep "," supportedSystems} ${config.age.secrets.hydra-ssh-key-priv.path} ${toString nrCores} ${toString speedFactor} ${lib.concatStringsSep "," supportedFeatures} - ${publicHostKey}";
|
|
|
|
|
|
|
|
# TODO:
|
|
|
|
# - generalize to new architectures
|
|
|
|
# - generalize to new features
|
|
|
|
baremetalBuilders = lib.concatStringsSep "\n"
|
|
|
|
(map (n: mkBaremetalBuilder {
|
|
|
|
nrCores = 40; # TODO: do not hardcode this, use the node's builder configuration.
|
|
|
|
publicHostKey = ssh-keys.machines.${n};
|
|
|
|
host = nodes.${n}.config.networking.fqdn;
|
|
|
|
}) cfg.builders);
|
2024-06-24 14:45:59 +00:00
|
|
|
in {
|
|
|
|
options.bagel.services.hydra = with lib; {
|
|
|
|
enable = mkEnableOption "Hydra coordinator";
|
|
|
|
|
|
|
|
dbi = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "DBI connection string for the Hydra postgres database";
|
|
|
|
};
|
2024-07-09 22:43:03 +00:00
|
|
|
|
|
|
|
builders = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
description = "List of builders to configure for Hydra";
|
|
|
|
example = [ "builder-0" "builder-1" ];
|
|
|
|
};
|
2024-06-24 14:45:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
2024-07-09 22:43:03 +00:00
|
|
|
# TODO: we should assert or warn that the builders
|
|
|
|
# does indeed have our public SSH key and are *builders*
|
|
|
|
# as a simple evaluation preflight check.
|
|
|
|
|
2024-06-24 18:59:19 +00:00
|
|
|
age.secrets.hydra-s3-credentials.file = ../../secrets/hydra-s3-credentials.age;
|
|
|
|
|
|
|
|
age.secrets.hydra-ssh-key-priv.owner = "hydra-queue-runner";
|
|
|
|
age.secrets.hydra-ssh-key-priv.file = ../../secrets/hydra-ssh-key-priv.age;
|
|
|
|
|
2024-06-24 14:45:59 +00:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d /var/cache/hydra 0755 hydra hydra - -"
|
|
|
|
"d ${narCacheDir} 0755 hydra hydra 1d -"
|
|
|
|
];
|
|
|
|
|
|
|
|
# XXX: Otherwise services.hydra-dev overwrites it to only hydra-queue-runner...
|
|
|
|
#
|
|
|
|
# Can be removed once this is added to some common config template.
|
|
|
|
nix.settings.trusted-users = [ "root" "@wheel" ];
|
|
|
|
|
|
|
|
services.hydra-dev = {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
listenHost = "localhost";
|
|
|
|
port = port;
|
|
|
|
dbi = cfg.dbi;
|
|
|
|
|
2024-07-07 21:53:21 +00:00
|
|
|
hydraURL = "https://hydra.forkos.org";
|
2024-06-24 14:45:59 +00:00
|
|
|
useSubstitutes = false;
|
|
|
|
|
2024-07-07 21:53:21 +00:00
|
|
|
notificationSender = "hydra@forkos.org";
|
2024-06-24 14:45:59 +00:00
|
|
|
|
2024-06-24 18:59:37 +00:00
|
|
|
# XXX: hydra overlay sets pkgs.hydra, but hydra's nixos module uses
|
|
|
|
# pkgs.hydra_unstable...
|
|
|
|
package = pkgs.hydra;
|
|
|
|
|
2024-06-24 18:59:19 +00:00
|
|
|
buildMachinesFiles = [
|
2024-07-09 23:13:10 +00:00
|
|
|
(pkgs.writeText "hydra-builders.conf" baremetalBuilders)
|
2024-06-24 18:59:19 +00:00
|
|
|
];
|
|
|
|
|
2024-06-24 14:45:59 +00:00
|
|
|
extraConfig = ''
|
|
|
|
store_uri = s3://bagel-cache?${mkCacheSettings {
|
|
|
|
endpoint = "s3.delroth.net";
|
|
|
|
region = "garage";
|
|
|
|
|
2024-06-24 16:03:07 +00:00
|
|
|
#secret-key = "TODO";
|
2024-06-24 14:45:59 +00:00
|
|
|
|
|
|
|
compression = "zstd";
|
|
|
|
log-compression = "br";
|
|
|
|
ls-compression = "br";
|
|
|
|
|
|
|
|
write-nar-listing = "1";
|
|
|
|
}}
|
|
|
|
|
|
|
|
server_store_uri = https://bagel-cache.s3-web.delroth.net?local-nar-cache=${narCacheDir}
|
|
|
|
binary_cache_public_url = https://bagel-cache.s3-web.delroth.net
|
|
|
|
log_prefix = https://bagel-cache.s3-web.delroth.net
|
|
|
|
|
|
|
|
upload_logs_to_binary_cache = true
|
|
|
|
|
|
|
|
evaluator_workers = 4
|
|
|
|
evaluator_max_memory_size = 4096
|
|
|
|
max_concurrent_evals = 1
|
|
|
|
|
|
|
|
allow_import_from_derivation = false
|
|
|
|
|
|
|
|
max_output_size = ${builtins.toString (3 * 1024 * 1024 * 1024)}
|
|
|
|
max_db_connections = 100
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-06-24 16:03:07 +00:00
|
|
|
systemd.services.hydra-queue-runner.serviceConfig.EnvironmentFile =
|
2024-06-24 18:59:19 +00:00
|
|
|
config.age.secrets.hydra-s3-credentials.path;
|
2024-06-24 16:03:07 +00:00
|
|
|
|
2024-06-24 14:45:59 +00:00
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
enableReload = true;
|
|
|
|
|
|
|
|
recommendedBrotliSettings = true;
|
|
|
|
recommendedGzipSettings = true;
|
|
|
|
recommendedOptimisation = true;
|
|
|
|
recommendedProxySettings = true;
|
|
|
|
recommendedTlsSettings = true;
|
|
|
|
recommendedZstdSettings = true;
|
|
|
|
|
|
|
|
proxyTimeout = "900s";
|
|
|
|
|
|
|
|
appendConfig = ''
|
|
|
|
worker_processes auto;
|
|
|
|
'';
|
|
|
|
|
2024-07-07 21:53:21 +00:00
|
|
|
virtualHosts."hydra.forkos.org" = {
|
2024-06-24 14:45:59 +00:00
|
|
|
forceSSL = true;
|
|
|
|
enableACME = true;
|
|
|
|
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://127.0.0.1:${builtins.toString port}";
|
|
|
|
};
|
|
|
|
|
|
|
|
locations."/static/" = {
|
|
|
|
alias = "${config.services.hydra-dev.package}/libexec/hydra/root/static/";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = [ 80 443 ];
|
|
|
|
};
|
|
|
|
}
|