1{
2 config,
3 pkgs,
4 lib,
5 ...
6}:
7
8with lib;
9
10let
11 cfg = config.services.ecs-agent;
12in
13{
14 options.services.ecs-agent = {
15 enable = mkEnableOption "Amazon ECS agent";
16
17 package = mkPackageOption pkgs "ecs-agent" { };
18
19 extra-environment = mkOption {
20 type = types.attrsOf types.str;
21 description = "The environment the ECS agent should run with. See the ECS agent documentation for keys that work here.";
22 default = { };
23 };
24 };
25
26 config = lib.mkIf cfg.enable {
27 # This service doesn't run if docker isn't running, and unlike potentially remote services like e.g., postgresql, docker has
28 # to be running locally so `docker.enable` will always be set if the ECS agent is enabled.
29 virtualisation.docker.enable = true;
30
31 systemd.services.ecs-agent = {
32 inherit (cfg.package.meta) description;
33 after = [ "network.target" ];
34 wantedBy = [ "multi-user.target" ];
35
36 environment = cfg.extra-environment;
37
38 script = ''
39 if [ ! -z "$ECS_DATADIR" ]; then
40 mkdir -p "$ECS_DATADIR"
41 fi
42 ${cfg.package}/bin/agent
43 '';
44 };
45 };
46}