summaryrefslogtreecommitdiff
path: root/modules/nixos/server/services/hercules.nix
blob: 7b55f6c6a4cad73bee356bdf53cdf6c6f6af6e84 (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
50
51
52
53
54
55
56
57
58
{
  config,
  lib,
  nixpkgs,
  pkgs,
  self,
  ...
}: let
  cfg = config.getchoo.server.services.hercules-ci;
  inherit (lib) mkEnableOption mkIf;
in {
  options.getchoo.server.services.hercules-ci = {
    enable = mkEnableOption "enable hercules-ci";
    secrets.enable = mkEnableOption "manage secrets for hercules-ci";
  };

  config = mkIf cfg.enable {
    age.secrets = let
      baseDir = "${self}/secrets/hosts/${config.networking.hostName}";
      hercArgs = {
        mode = "400";
        owner = "hercules-ci-agent";
        group = "hercules-ci-agent";
      };
    in
      mkIf cfg.secrets.enable {
        binaryCache =
          {
            file = "${baseDir}/binaryCache.age";
          }
          // hercArgs;

        clusterToken =
          {
            file = "${baseDir}/clusterToken.age";
          }
          // hercArgs;

        secretsJson =
          {
            file = "${baseDir}/secretsJson.age";
          }
          // hercArgs;
      };

    services = {
      hercules-ci-agent = {
        enable = true;
        package = (import nixpkgs {inherit (pkgs) system;}).hercules-ci-agent;
        settings = {
          binaryCachesPath = config.age.secrets.binaryCache.path;
          clusterJoinTokenPath = config.age.secrets.clusterToken.path;
          secretsJsonPath = config.age.secrets.secretsJson.path;
        };
      };
    };
  };
}