2023-12-07 09:53:36 +10:00
|
|
|
{ pkgs, config, ... }:
|
2022-12-31 07:24:17 +01:00
|
|
|
{
|
2020-04-17 22:12:42 +02:00
|
|
|
config = {
|
2021-09-29 19:50:50 +02:00
|
|
|
sops.secrets.hydra-admin-password.owner = "hydra";
|
|
|
|
sops.secrets.hydra-users.owner = "hydra";
|
2021-09-25 22:35:51 +02:00
|
|
|
|
2023-04-12 12:35:41 +10:00
|
|
|
nix.settings.allowed-uris = [
|
|
|
|
"https://github.com/nix-community/"
|
|
|
|
"https://github.com/NixOS/"
|
|
|
|
];
|
2022-08-14 15:31:50 +02:00
|
|
|
|
2023-03-21 06:40:06 +01: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";
|
|
|
|
};
|
|
|
|
|
2020-04-17 22:12:42 +02:00
|
|
|
services.hydra = {
|
|
|
|
enable = true;
|
2022-10-30 06:38:47 +10:00
|
|
|
# remote builders set in /etc/nix/machines + localhost
|
|
|
|
buildMachinesFiles = [
|
2024-01-07 12:44:01 +10:00
|
|
|
(pkgs.runCommand "etc-nix-machines"
|
|
|
|
{
|
|
|
|
machines = config.environment.etc."nix/machines".text;
|
|
|
|
} ''
|
|
|
|
printf "$machines" > $out
|
|
|
|
substituteInPlace $out --replace 'ssh-ng://' 'ssh://'
|
|
|
|
'')
|
2022-10-30 06:38:47 +10:00
|
|
|
|
|
|
|
(pkgs.writeText "local" ''
|
|
|
|
localhost x86_64-linux,builtin - 8 1 nixos-test,big-parallel,kvm - -
|
|
|
|
'')
|
|
|
|
];
|
2021-03-06 13:59:44 +01:00
|
|
|
hydraURL = "https://hydra.nix-community.org";
|
2020-04-17 22:12:42 +02:00
|
|
|
notificationSender = "hydra@hydra.nix-community.org";
|
2023-04-14 12:56:31 +10:00
|
|
|
port = 3000;
|
2020-04-17 22:12:42 +02:00
|
|
|
useSubstitutes = true;
|
|
|
|
extraConfig = ''
|
|
|
|
max_output_size = ${builtins.toString (8 * 1024 * 1024 * 1024)}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-04-21 23:23:08 +02:00
|
|
|
services.nginx.virtualHosts = {
|
|
|
|
"hydra.nix-community.org" = {
|
|
|
|
forceSSL = true;
|
|
|
|
enableACME = true;
|
2023-01-01 15:30:41 +01:00
|
|
|
locations."/".proxyPass = "http://localhost:${toString config.services.hydra.port}";
|
2021-04-21 23:23:08 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-12-07 09:53:36 +10:00
|
|
|
# Create user accounts
|
|
|
|
# format: user;role;password-hash;email-address;full-name
|
|
|
|
# Password hash is computed by applying sha1 to the password.
|
2021-03-06 18:03:01 +01:00
|
|
|
systemd.services.hydra-post-init = {
|
2020-04-17 22:12:42 +02:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
TimeoutStartSec = "60";
|
|
|
|
};
|
2022-12-31 07:24:17 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "hydra-server.service" ];
|
|
|
|
requires = [ "hydra-server.service" ];
|
2020-04-17 22:12:42 +02:00
|
|
|
environment = {
|
2023-04-14 12:56:31 +10:00
|
|
|
inherit (config.systemd.services.hydra-init.environment) HYDRA_DBI;
|
2020-04-17 22:12:42 +02:00
|
|
|
};
|
2023-04-14 12:56:31 +10:00
|
|
|
path = [ config.services.hydra.package pkgs.netcat ];
|
2020-04-17 22:12:42 +02:00
|
|
|
script = ''
|
|
|
|
set -e
|
2021-03-06 20:36:42 +01:00
|
|
|
while IFS=';' read -r user role passwordhash email fullname; do
|
2021-03-06 18:03:01 +01:00
|
|
|
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
|
2021-03-06 20:36:42 +01:00
|
|
|
hydra-create-user "''${opts[@]}"
|
2023-12-07 09:53:36 +10:00
|
|
|
done < ${config.sops.secrets.hydra-users.path}
|
2020-04-17 22:12:42 +02:00
|
|
|
|
2023-04-14 12:56:31 +10:00
|
|
|
while ! nc -z localhost ${toString config.services.hydra.port}; do
|
2020-04-17 22:12:42 +02:00
|
|
|
sleep 1
|
|
|
|
done
|
2020-01-12 21:15:32 +01:00
|
|
|
|
2023-12-07 09:53:36 +10:00
|
|
|
export HYDRA_ADMIN_PASSWORD=$(cat ${config.sops.secrets.hydra-admin-password.path})
|
2023-04-14 12:56:31 +10:00
|
|
|
export URL=http://localhost:${toString config.services.hydra.port}
|
2022-05-14 22:18:06 +02:00
|
|
|
'';
|
2020-04-17 22:12:42 +02:00
|
|
|
};
|
2020-01-12 21:15:32 +01:00
|
|
|
};
|
|
|
|
}
|