about summary refs log tree commit diff
path: root/modules/services/buildkite/default.nix
blob: a1bd021c187847745cb265dd8891c3b41d331835 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{ config, pkgs, lib, ... }:
let
  cfg = config.my.services.buildkite;
  agents = lib.range 1 5;
  secrets = config.age.secrets;
in {
  options.my.services.buildkite = with lib; {
    enable = mkEnableOption "buildkite agent";
  };

  config = lib.mkIf cfg.enable {
    # see https://buildkite.com/docs/agent/v3
    # and https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/continuous-integration/buildkite-agents.nix
    services.buildkite-agents = lib.listToAttrs (map (n: rec {
      name = "builder-${toString n}";
      value = {
        inherit name;
        enable = true;
        tokenPath = secrets."buildkite/agent".path;
        runtimePackages = with pkgs; [
          bash
          coreutils
          curl
          git
          gnutar
          gzip
          jq
          nix
        ];
      };
    }) agents);

    # Set up a group for all Buildkite agent users
    users = {
      groups.buildkite-agents = { };
      users = builtins.listToAttrs (map (n: rec {
        name = "buildkite-agent-builder-${toString n}";
        value = {
          isSystemUser = true;
          group = lib.mkForce "buildkite-agents";
          extraGroups = [ name "docker" ];
        };
      }) agents);
    };
  };
}