2021-04-09 19:04:50 +02:00
|
|
|
# Configuration for the TVL buildkite agents.
|
2021-04-10 13:40:06 +02:00
|
|
|
{ config, depot, pkgs, lib, ... }:
|
2021-04-09 19:04:50 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.depot.buildkite;
|
|
|
|
agents = lib.range 1 cfg.agentCount;
|
|
|
|
description = "Buildkite agents for TVL";
|
|
|
|
|
2021-12-06 17:19:05 +01:00
|
|
|
besadiiWithConfig = name: pkgs.writeShellScript "besadii-whitby" ''
|
2021-12-10 14:11:19 +01:00
|
|
|
export BESADII_CONFIG=/run/agenix/buildkite-besadii-config
|
2021-12-06 17:19:05 +01:00
|
|
|
exec -a ${name} ${depot.ops.besadii}/bin/besadii "$@"
|
2021-11-29 16:53:54 +01:00
|
|
|
'';
|
|
|
|
|
2021-04-09 19:04:50 +02:00
|
|
|
# All Buildkite hooks are actually besadii, but it's being invoked
|
|
|
|
# with different names.
|
2022-01-30 17:06:58 +01:00
|
|
|
buildkiteHooks = pkgs.runCommandNoCC "buildkite-hooks" { } ''
|
2021-04-09 19:04:50 +02:00
|
|
|
mkdir -p $out/bin
|
2021-12-06 17:19:05 +01:00
|
|
|
ln -s ${besadiiWithConfig "post-command"} $out/bin/post-command
|
2021-04-09 19:04:50 +02:00
|
|
|
'';
|
2021-12-10 19:44:37 +01:00
|
|
|
|
2021-12-10 21:37:57 +01:00
|
|
|
credentialHelper = pkgs.writeShellScriptBin "git-credential-gerrit-creds" ''
|
2021-12-10 19:44:37 +01:00
|
|
|
echo 'username=buildkite'
|
|
|
|
echo "password=$(jq -r '.gerritPassword' /run/agenix/buildkite-besadii-config)"
|
|
|
|
'';
|
2022-01-30 17:06:58 +01:00
|
|
|
in
|
|
|
|
{
|
2021-04-09 19:04:50 +02:00
|
|
|
options.services.depot.buildkite = {
|
|
|
|
enable = lib.mkEnableOption description;
|
|
|
|
agentCount = lib.mkOption {
|
|
|
|
type = lib.types.int;
|
|
|
|
description = "Number of Buildkite agents to launch";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
# Run the Buildkite agents using the default upstream module.
|
2022-01-30 17:06:58 +01:00
|
|
|
services.buildkite-agents = builtins.listToAttrs (map
|
|
|
|
(n: rec {
|
|
|
|
name = "whitby-${toString n}";
|
|
|
|
value = {
|
|
|
|
inherit name;
|
|
|
|
enable = true;
|
|
|
|
tokenPath = "/run/agenix/buildkite-agent-token";
|
|
|
|
hooks.post-command = "${buildkiteHooks}/bin/post-command";
|
2021-12-10 08:47:29 +01:00
|
|
|
|
2022-01-30 17:06:58 +01:00
|
|
|
runtimePackages = with pkgs; [
|
|
|
|
bash
|
|
|
|
coreutils
|
|
|
|
credentialHelper
|
|
|
|
curl
|
|
|
|
git
|
|
|
|
gnutar
|
|
|
|
gzip
|
|
|
|
jq
|
|
|
|
nix
|
|
|
|
];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
agents);
|
2021-04-09 17:36:57 +02:00
|
|
|
|
|
|
|
# Set up a group for all Buildkite agent users
|
|
|
|
users = {
|
2022-01-30 17:06:58 +01:00
|
|
|
groups.buildkite-agents = { };
|
|
|
|
users = builtins.listToAttrs (map
|
|
|
|
(n: rec {
|
|
|
|
name = "buildkite-agent-whitby-${toString n}";
|
|
|
|
value = {
|
|
|
|
isSystemUser = true;
|
|
|
|
group = lib.mkForce "buildkite-agents";
|
|
|
|
extraGroups = [ name "docker" ];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
agents);
|
2021-04-09 17:36:57 +02:00
|
|
|
};
|
2021-04-09 19:04:50 +02:00
|
|
|
};
|
|
|
|
}
|