summary refs log tree commit diff
path: root/nixos/modules/services/security/hologram-agent.nix
blob: e29267e50003bc7ef8d974d96cfbb467d87f0d7d (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
47
48
49
50
51
52
53
54
55
56
57
58
{pkgs, config, lib, ...}:

with lib;

let
  cfg = config.services.hologram-agent;

  cfgFile = pkgs.writeText "hologram-agent.json" (builtins.toJSON {
    host = cfg.dialAddress;
  });
in {
  options = {
    services.hologram-agent = {
      enable = mkOption {
        type = types.bool;
        default = false;
        description = "Whether to enable the Hologram agent for AWS instance credentials";
      };

      dialAddress = mkOption {
        type        = types.str;
        default     = "localhost:3100";
        description = "Hologram server and port.";
      };

      httpPort = mkOption {
        type        = types.str;
        default     = "80";
        description = "Port for metadata service to listen on.";
      };

    };
  };

  config = mkIf cfg.enable {
    boot.kernelModules = [ "dummy" ];

    networking.interfaces.dummy0.ipv4.addresses = [
      { address = "169.254.169.254"; prefixLength = 32; }
    ];

    systemd.services.hologram-agent = {
      description = "Provide EC2 instance credentials to machines outside of EC2";
      after       = [ "network.target" ];
      wantedBy    = [ "multi-user.target" ];
      requires    = [ "network-link-dummy0.service" "network-addresses-dummy0.service" ];
      preStart = ''
        /run/current-system/sw/bin/rm -fv /run/hologram.sock
      '';
      serviceConfig = {
        ExecStart = "${pkgs.hologram}/bin/hologram-agent -debug -conf ${cfgFile} -port ${cfg.httpPort}";
      };
    };

  };

  meta.maintainers = with lib.maintainers; [ ];
}