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-11-29 16:53:54 +01:00
|
|
|
export BESADII_CONFIG=/etc/secrets/besadii.json
|
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
|
|
|
'';
|
|
|
|
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;
|
2021-12-10 08:29:41 +01:00
|
|
|
tokenPath = "/run/agenix/buildkite-agent-token";
|
2021-12-10 08:20:51 +01:00
|
|
|
runtimePackages = with pkgs; [ curl jq ];
|
2021-04-09 19:04:50 +02:00
|
|
|
hooks.post-command = "${buildkiteHooks}/bin/post-command";
|
|
|
|
};
|
|
|
|
}) 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";
|
|
|
|
extraGroups = [ name ];
|
|
|
|
};
|
2021-04-09 17:36:57 +02:00
|
|
|
}) agents);
|
|
|
|
};
|
2021-04-09 19:04:50 +02:00
|
|
|
};
|
|
|
|
}
|