summaryrefslogtreecommitdiff
path: root/modules/nixos/traits/hercules.nix
blob: fc3dbd0cf3cd4d08e15f3a432df050552a8c4d1a (plain)
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
47
48
49
{
  config,
  lib,
  unstable,
  secretsDir,
  ...
}: let
  cfg = config.traits.hercules-ci;
in {
  options.traits.hercules-ci = {
    enable = lib.mkEnableOption "hercules-ci";
    manageSecrets = lib.mkEnableOption "automatic secrets management";
  };

  config = lib.mkIf cfg.enable (
    lib.mkMerge [
      {
        services = {
          hercules-ci-agent = {
            enable = true;
            package = unstable.hercules-ci-agent;
            settings = {
              binaryCachesPath = config.age.secrets.binaryCache.path;
              clusterJoinTokenPath = config.age.secrets.clusterToken.path;
              secretsJsonPath = config.age.secrets.secretsJson.path;
            };
          };
        };
      }

      (let
        hercArgs = {
          mode = "400";
          owner = "hercules-ci-agent";
          group = "hercules-ci-agent";
        };

        mkSecrets = lib.mapAttrs (_: file: lib.recursiveUpdate hercArgs {inherit file;});
      in
        lib.mkIf cfg.manageSecrets {
          age.secrets = mkSecrets {
            binaryCache = secretsDir + "/binaryCache.age";
            clusterToken = secretsDir + "/clusterToken.age";
            secretsJson = secretsDir + "/secretsJson.age";
          };
        })
    ]
  );
}