summary refs log tree commit diff
path: root/nixos/modules/virtualisation/ecs-agent.nix
blob: 93fefe56d1a5fb4e8c91182da21bd0e75fc029c5 (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
{ config, pkgs, lib, ... }:

with lib;

let
  cfg = config.services.ecs-agent;
in {
  options.services.ecs-agent = {
    enable = mkEnableOption "Amazon ECS agent";

    package = mkOption {
      type = types.path;
      description = "The ECS agent package to use";
      default = pkgs.ecs-agent;
      defaultText = "pkgs.ecs-agent";
    };

    extra-environment = mkOption {
      type = types.attrsOf types.str;
      description = "The environment the ECS agent should run with. See the ECS agent documentation for keys that work here.";
      default = {};
    };
  };

  config = lib.mkIf cfg.enable {
    # This service doesn't run if docker isn't running, and unlike potentially remote services like e.g., postgresql, docker has
    # to be running locally so `docker.enable` will always be set if the ECS agent is enabled.
    virtualisation.docker.enable = true;

    systemd.services.ecs-agent = {
      inherit (cfg.package.meta) description;
      after    = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];

      environment = cfg.extra-environment;

      script = ''
        if [ ! -z "$ECS_DATADIR" ]; then
          mkdir -p "$ECS_DATADIR"
        fi
        ${cfg.package}/bin/agent
      '';
    };
  };
}