infra/modules/nixos/hydra.nix

116 lines
3.4 KiB
Nix
Raw Normal View History

2024-11-21 13:36:17 +10:00
{
pkgs,
config,
lib,
...
}:
let
inherit (lib) concatStringsSep;
localSystems = [
"builtin"
config.nixpkgs.hostPlatform.system
] ++ config.nix.settings.extra-platforms;
in
2022-12-31 07:24:17 +01:00
{
2024-10-27 13:41:54 +10:00
sops.secrets.hydra-admin-password.owner = "hydra";
sops.secrets.hydra-users.owner = "hydra";
2021-09-25 22:35:51 +02:00
2024-10-27 13:41:54 +10:00
# hydra-queue-runner needs to read this key for remote building
sops.secrets.id_buildfarm.owner = "hydra-queue-runner";
2024-11-21 13:36:17 +10:00
nix.settings.keep-outputs = lib.mkForce false;
2024-10-27 13:41:54 +10:00
nix.settings.allowed-uris = [
"git+https:"
"github:"
"gitlab:"
"https:"
"sourcehut:"
];
2024-10-27 13:41:54 +10:00
sops.secrets.id_buildfarm = { };
2024-10-27 13:41:54 +10:00
# delete build logs older than 30 days
systemd.services.hydra-delete-old-logs = {
startAt = "Sun 05:45";
serviceConfig.ExecStart = "${pkgs.findutils}/bin/find /var/lib/hydra/build-logs -type f -mtime +30 -delete";
};
2023-03-21 06:40:06 +01:00
2024-11-18 11:01:54 +10:00
# not currently needed
systemd.services = {
hydra-check-space.enable = false;
hydra-send-stats.enable = false;
};
2024-10-27 13:41:54 +10:00
services.hydra = {
enable = true;
# remote builders set in /etc/nix/machines + localhost
buildMachinesFiles = [
(pkgs.runCommand "etc-nix-machines" { machines = config.environment.etc."nix/machines".text; } ''
printf "$machines" > $out
2024-10-27 13:41:54 +10:00
substituteInPlace $out --replace-fail 'ssh-ng://' 'ssh://'
substituteInPlace $out --replace-fail ' 80 ' ' 3 '
substituteInPlace $out --replace-fail ' 8 ' ' 1 '
2024-10-27 13:41:54 +10:00
'')
2024-10-27 13:41:54 +10:00
(pkgs.writeText "local" ''
2024-11-21 13:36:17 +10:00
localhost ${concatStringsSep "," localSystems} - 3 1 ${concatStringsSep "," config.nix.settings.system-features} - -
2024-10-27 13:41:54 +10:00
'')
];
hydraURL = "https://hydra.nix-community.org";
notificationSender = "hydra@hydra.nix-community.org";
port = 3000;
useSubstitutes = true;
extraConfig = ''
evaluator_max_memory_size = 4096
evaluator_workers = 8
max_concurrent_evals = 2
max_output_size = ${builtins.toString (8 * 1024 * 1024 * 1024)}
'';
};
2024-10-27 13:41:54 +10:00
services.nginx.virtualHosts."hydra.nix-community.org" = {
locations."/".proxyPass = "http://localhost:${toString config.services.hydra.port}";
};
2021-04-21 23:23:08 +02:00
2024-10-27 13:41:54 +10:00
# Create user accounts
# format: user;role;password-hash;email-address;full-name
# Password hash is computed by applying sha1 to the password.
systemd.services.hydra-post-init = {
serviceConfig = {
Type = "oneshot";
TimeoutStartSec = "60";
};
2024-11-09 21:49:54 +10:00
wantedBy = [ config.systemd.targets.multi-user.name ];
after = [ config.systemd.services.hydra-server.name ];
requires = [ config.systemd.services.hydra-server.name ];
2024-10-27 13:41:54 +10:00
environment = {
inherit (config.systemd.services.hydra-init.environment) HYDRA_DBI;
};
path = [
config.services.hydra.package
pkgs.netcat
];
script = ''
set -e
while IFS=';' read -r user role passwordhash email fullname; do
opts=("$user" "--role" "$role" "--password-hash" "$passwordhash")
if [[ -n "$email" ]]; then
opts+=("--email-address" "$email")
fi
if [[ -n "$fullname" ]]; then
opts+=("--full-name" "$fullname")
fi
hydra-create-user "''${opts[@]}"
done < ${config.sops.secrets.hydra-users.path}
2024-10-27 13:41:54 +10:00
while ! nc -z localhost ${toString config.services.hydra.port}; do
sleep 1
done
2020-01-12 21:15:32 +01:00
2024-10-27 13:41:54 +10:00
export HYDRA_ADMIN_PASSWORD=$(cat ${config.sops.secrets.hydra-admin-password.path})
export URL=http://localhost:${toString config.services.hydra.port}
'';
2020-01-12 21:15:32 +01:00
};
}