2022-04-10 22:40:01 +02:00
|
|
|
{ hydra }:
|
2020-01-12 21:15:32 +01:00
|
|
|
{ lib, pkgs, config, ... }:
|
2020-04-17 22:12:42 +02:00
|
|
|
|
|
|
|
with lib;
|
2020-01-12 21:15:32 +01:00
|
|
|
let
|
2020-04-17 22:12:42 +02:00
|
|
|
cfg = config;
|
2020-01-12 21:15:32 +01:00
|
|
|
|
2020-04-17 22:12:42 +02:00
|
|
|
hydraPort = 3000;
|
2021-01-03 00:07:49 +01:00
|
|
|
in
|
|
|
|
{
|
2020-04-17 22:12:42 +02:00
|
|
|
options.services.hydra = {
|
|
|
|
adminPasswordFile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "The initial password for the Hydra admin account";
|
|
|
|
};
|
2020-01-12 21:15:32 +01:00
|
|
|
|
2021-03-06 18:03:01 +01:00
|
|
|
usersFile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
declarative user accounts for hydra.
|
|
|
|
format: user;role;password-hash;email-address;full-name
|
|
|
|
Password hash is computed by applying sha1 to the password.
|
|
|
|
'';
|
|
|
|
};
|
2020-01-12 21:15:32 +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
|
|
|
|
2020-04-17 22:12:42 +02:00
|
|
|
nixpkgs.config = {
|
|
|
|
whitelistedLicenses = with lib.licenses; [
|
|
|
|
unfreeRedistributable
|
|
|
|
issl
|
|
|
|
];
|
|
|
|
allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
|
|
|
|
"cudnn_cudatoolkit"
|
|
|
|
"cudatoolkit"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2022-04-10 22:40:01 +02:00
|
|
|
services.hydra.package = hydra.defaultPackage.${pkgs.system};
|
2022-04-10 20:57:52 +02:00
|
|
|
|
2021-11-01 08:57:51 +01:00
|
|
|
sops.secrets.nix-community-cachix = {
|
|
|
|
owner = "hydra-queue-runner";
|
|
|
|
sopsFile = ../../roles/nix-community-cache.yaml;
|
|
|
|
};
|
2022-08-13 14:34:38 +02:00
|
|
|
sops.secrets.id_buildfarm = {};
|
|
|
|
|
2020-04-17 22:12:42 +02:00
|
|
|
|
|
|
|
services.hydra = {
|
|
|
|
enable = true;
|
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";
|
|
|
|
port = hydraPort;
|
|
|
|
useSubstitutes = true;
|
2022-05-14 22:18:06 +02:00
|
|
|
adminPasswordFile = config.sops.secrets.hydra-admin-password.path;
|
2022-08-13 14:34:38 +02:00
|
|
|
buildMachinesFiles = [
|
|
|
|
(pkgs.writeText "builders" ''
|
|
|
|
localhost x86_64-linux,builtin - 8 1 nixos-test,big-parallel,kvm -
|
|
|
|
ssh-ng://nix@build04.nix-community.org aarch64-linux ${config.sops.secrets.id_buildfarm.path} 4 1 nixos-test,big-parallel,kvm -
|
|
|
|
'')
|
|
|
|
];
|
2021-03-20 07:09:00 +01:00
|
|
|
|
2022-05-14 22:18:06 +02:00
|
|
|
usersFile = config.sops.secrets.hydra-users.path;
|
2020-04-17 22:12:42 +02:00
|
|
|
extraConfig = ''
|
|
|
|
max_output_size = ${builtins.toString (8 * 1024 * 1024 * 1024)}
|
2021-11-01 08:57:51 +01:00
|
|
|
|
|
|
|
<runcommand>
|
|
|
|
command = ${pkgs.writeShellScript "cachix-upload" ''
|
|
|
|
export PATH=${config.nix.package}/bin
|
|
|
|
${pkgs.jq}/bin/jq -r '.outputs | .[] | .path' < $HYDRA_JSON | \
|
|
|
|
${pkgs.cachix}/bin/cachix -c ${config.sops.secrets.nix-community-cachix.path} push nix-community
|
|
|
|
''}
|
|
|
|
</runcommand>
|
2020-04-17 22:12:42 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-10-21 19:15:05 +02:00
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
2021-01-03 00:53:49 +00:00
|
|
|
settings = {
|
|
|
|
effective_cache_size = "4GB";
|
|
|
|
shared_buffers = "4GB";
|
|
|
|
};
|
2020-10-21 19:15:05 +02:00
|
|
|
};
|
|
|
|
|
2022-08-13 14:34:38 +02:00
|
|
|
nix.extraOptions = "allowed-uris = https://github.com/nix-community/ https://github.com/NixOS/";
|
2020-04-17 22:12:42 +02:00
|
|
|
|
2021-04-21 23:23:08 +02:00
|
|
|
services.nginx.virtualHosts = {
|
|
|
|
"hydra.nix-community.org" = {
|
|
|
|
forceSSL = true;
|
|
|
|
enableACME = true;
|
|
|
|
locations."/".proxyPass = "http://localhost:${toString (config.services.hydra.port)}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-04-17 22:12:42 +02:00
|
|
|
# Create a admin user and configure a declarative project
|
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";
|
|
|
|
};
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2021-01-03 00:07:49 +01:00
|
|
|
after = [ "hydra-server.service" ];
|
2020-04-17 22:12:42 +02:00
|
|
|
requires = [ "hydra-server.service" ];
|
|
|
|
environment = {
|
|
|
|
inherit (cfg.systemd.services.hydra-init.environment) HYDRA_DBI;
|
|
|
|
};
|
2022-04-10 23:06:17 +02:00
|
|
|
path = with pkgs; [ config.services.hydra.package 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[@]}"
|
2021-03-06 18:03:01 +01:00
|
|
|
done < ${cfg.services.hydra.usersFile}
|
2020-04-17 22:12:42 +02:00
|
|
|
|
|
|
|
while ! nc -z localhost ${toString hydraPort}; do
|
|
|
|
sleep 1
|
|
|
|
done
|
2020-01-12 21:15:32 +01:00
|
|
|
|
2021-03-06 18:03:01 +01:00
|
|
|
export HYDRA_ADMIN_PASSWORD=$(cat ${cfg.services.hydra.adminPasswordFile})
|
|
|
|
export URL=http://localhost:${toString hydraPort}
|
2022-05-14 22:18:06 +02:00
|
|
|
'';
|
2020-04-17 22:12:42 +02:00
|
|
|
};
|
2020-01-12 21:15:32 +01:00
|
|
|
};
|
|
|
|
}
|