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.
|
2021-04-10 13:40:06 +02: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)"
|
|
|
|
'';
|
2021-04-09 19:04:50 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
services.buildkite-agents = builtins.listToAttrs (map
|
|
|
|
(n: rec {
|
|
|
|
name = "whitby-${toString n}";
|
|
|
|
value = {
|
|
|
|
inherit name;
|
|
|
|
enable = true;
|
2022-05-22 23:51:49 +02:00
|
|
|
tokenPath = config.age.secretsDir + "/buildkite-agent-token";
|
2022-05-25 18:17:25 +02:00
|
|
|
privateSshKeyPath = config.age.secretsDir + "/buildkite-private-key";
|
2021-04-09 19:04:50 +02:00
|
|
|
hooks.post-command = "${buildkiteHooks}/bin/post-command";
|
2021-12-10 08:47:29 +01:00
|
|
|
|
2021-12-10 15:16:35 +01:00
|
|
|
runtimePackages = with pkgs; [
|
|
|
|
bash
|
|
|
|
coreutils
|
2021-12-10 19:44:37 +01:00
|
|
|
credentialHelper
|
2021-12-10 08:47:29 +01:00
|
|
|
curl
|
2021-12-10 15:16:35 +01:00
|
|
|
git
|
2021-12-10 16:58:33 +01:00
|
|
|
gnutar
|
|
|
|
gzip
|
2021-12-10 08:47:29 +01:00
|
|
|
jq
|
2021-12-10 15:16:35 +01:00
|
|
|
nix
|
2021-12-10 08:47:29 +01:00
|
|
|
];
|
2021-04-09 19:04:50 +02:00
|
|
|
};
|
|
|
|
})
|
|
|
|
agents);
|
2021-04-09 17:36:57 +02:00
|
|
|
|
|
|
|
# Set up a group for all Buildkite agent users
|
|
|
|
users = {
|
|
|
|
groups.buildkite-agents = { };
|
2021-04-11 17:46:37 +02:00
|
|
|
users = builtins.listToAttrs (map
|
|
|
|
(n: rec {
|
2021-04-09 17:36:57 +02:00
|
|
|
name = "buildkite-agent-whitby-${toString n}";
|
2021-04-11 17:46:37 +02:00
|
|
|
value = {
|
2021-04-13 12:21:42 +02:00
|
|
|
isSystemUser = true;
|
2021-04-11 17:46:37 +02:00
|
|
|
group = lib.mkForce "buildkite-agents";
|
2021-12-19 03:35:48 +01:00
|
|
|
extraGroups = [ name "docker" ];
|
2021-04-11 17:46:37 +02:00
|
|
|
};
|
2021-04-09 17:36:57 +02:00
|
|
|
})
|
|
|
|
agents);
|
|
|
|
};
|
2021-04-09 19:04:50 +02:00
|
|
|
};
|
|
|
|
}
|