|
| 1 | +{ config, pkgs, lib, name, ... }: |
| 2 | +{ |
| 3 | + options = { |
| 4 | + package = lib.mkPackageOption pkgs "elasticmq-server-bin" { }; |
| 5 | + |
| 6 | + nodeAddress = { |
| 7 | + protocol = lib.mkOption { |
| 8 | + type = lib.types.str; |
| 9 | + default = "http"; |
| 10 | + }; |
| 11 | + host = lib.mkOption { |
| 12 | + type = lib.types.str; |
| 13 | + default = "localhost"; |
| 14 | + }; |
| 15 | + port = lib.mkOption { |
| 16 | + type = lib.types.port; |
| 17 | + default = 9324; |
| 18 | + }; |
| 19 | + contextPath = lib.mkOption { |
| 20 | + type = lib.types.str; |
| 21 | + default = ""; |
| 22 | + }; |
| 23 | + }; |
| 24 | + |
| 25 | + restSqs = lib.mkOption { |
| 26 | + type = lib.types.submodule { |
| 27 | + options = { |
| 28 | + enable = lib.mkOption { |
| 29 | + type = lib.types.bool; |
| 30 | + default = true; |
| 31 | + }; |
| 32 | + bindPort = lib.mkOption { |
| 33 | + type = lib.types.port; |
| 34 | + default = 9324; |
| 35 | + }; |
| 36 | + bindHost = lib.mkOption { |
| 37 | + type = lib.types.str; |
| 38 | + default = "0.0.0.0"; |
| 39 | + }; |
| 40 | + }; |
| 41 | + }; |
| 42 | + default = { }; |
| 43 | + }; |
| 44 | + |
| 45 | + restStats = lib.mkOption { |
| 46 | + type = lib.types.submodule { |
| 47 | + options = { |
| 48 | + enable = lib.mkOption { |
| 49 | + type = lib.types.bool; |
| 50 | + default = true; |
| 51 | + }; |
| 52 | + bindPort = lib.mkOption { |
| 53 | + type = lib.types.port; |
| 54 | + default = 9325; |
| 55 | + }; |
| 56 | + bindHost = lib.mkOption { |
| 57 | + type = lib.types.str; |
| 58 | + default = "0.0.0.0"; |
| 59 | + }; |
| 60 | + }; |
| 61 | + }; |
| 62 | + default = { }; |
| 63 | + }; |
| 64 | + |
| 65 | + generateNodeAddress = lib.mkOption { |
| 66 | + type = lib.types.bool; |
| 67 | + default = false; |
| 68 | + }; |
| 69 | + |
| 70 | + extraOptions = lib.mkOption { |
| 71 | + type = lib.types.lines; |
| 72 | + default = ""; |
| 73 | + description = "Additional raw HOCON options to append."; |
| 74 | + }; |
| 75 | + |
| 76 | + extraArgs = lib.mkOption { |
| 77 | + type = lib.types.listOf lib.types.str; |
| 78 | + default = [ ]; |
| 79 | + description = '' |
| 80 | + Extra args to pass down to ElasticMQ. |
| 81 | + ''; |
| 82 | + }; |
| 83 | + }; |
| 84 | + |
| 85 | + config.outputs.settings.processes."${name}" = |
| 86 | + let |
| 87 | + confFile = pkgs.writeText "elasticmq.conf" '' |
| 88 | + node-address.protocol = ${config.nodeAddress.protocol} |
| 89 | + node-address.host = ${config.nodeAddress.host} |
| 90 | + node-address.port = ${toString config.nodeAddress.port} |
| 91 | + node-address.context-path = "${config.nodeAddress.contextPath}" |
| 92 | +
|
| 93 | + rest-sqs.enabled = ${lib.boolToString config.restSqs.enable} |
| 94 | + rest-sqs.bind-port = ${toString config.restSqs.bindPort} |
| 95 | + rest-sqs.bind-hostname = "${config.restSqs.bindHost}" |
| 96 | +
|
| 97 | + rest-stats.enabled = ${lib.boolToString config.restStats.enable} |
| 98 | + rest-stats.bind-port = ${toString config.restStats.bindPort} |
| 99 | + rest-stats.bind-hostname = "${config.restStats.bindHost}" |
| 100 | +
|
| 101 | + generate-node-address = ${lib.boolToString config.generateNodeAddress} |
| 102 | +
|
| 103 | + ${config.extraOptions} |
| 104 | + ''; |
| 105 | + startCommand = pkgs.writeShellApplication { |
| 106 | + name = "start-elasticmq"; |
| 107 | + runtimeEnv = { |
| 108 | + JAVA_TOOL_OPTIONS = "-Dconfig.file=${confFile}"; |
| 109 | + }; |
| 110 | + text = '' |
| 111 | + exec ${lib.getExe config.package} ${lib.escapeShellArgs config.extraArgs} |
| 112 | + ''; |
| 113 | + }; |
| 114 | + in |
| 115 | + { |
| 116 | + command = startCommand; |
| 117 | + readiness_probe = lib.optionalAttrs config.restSqs.enable { |
| 118 | + http_get = { |
| 119 | + host = "127.0.0.1"; |
| 120 | + port = config.restSqs.bindPort; |
| 121 | + path = "/health"; |
| 122 | + }; |
| 123 | + initial_delay_seconds = 2; |
| 124 | + period_seconds = 10; |
| 125 | + timeout_seconds = 4; |
| 126 | + success_threshold = 1; |
| 127 | + failure_threshold = 5; |
| 128 | + }; |
| 129 | + # https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy |
| 130 | + availability = { |
| 131 | + restart = "on_failure"; |
| 132 | + max_restarts = 5; |
| 133 | + }; |
| 134 | + }; |
| 135 | +} |
0 commit comments