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