|
8 | 8 | pkgs,
|
9 | 9 | ...
|
10 | 10 | }:
|
11 |
| - |
12 |
| - with lib; |
13 |
| - |
14 | 11 | let
|
15 |
| - |
16 | 12 | mkProbeOptions = x: {
|
17 | 13 | options =
|
18 | 14 | {
|
19 |
| - enable = mkEnableOption "the ${x} probe"; |
| 15 | + enable = lib.mkEnableOption "the ${x} probe"; |
20 | 16 |
|
21 |
| - command = mkOption { |
22 |
| - type = types.str; |
| 17 | + command = lib.mkOption { |
| 18 | + type = lib.types.str; |
23 | 19 | description = "The command to execute for the ${x} check. Any necessary programs should be added to the healthcheck.runtimePackages option.";
|
24 | 20 | };
|
25 | 21 |
|
26 |
| - initialDelay = mkOption { |
27 |
| - type = types.int; |
| 22 | + initialDelay = lib.mkOption { |
| 23 | + type = lib.types.int; |
28 | 24 | default = 15;
|
29 | 25 | description = "Seconds to wait after the service is up before the first ${x} probe.";
|
30 | 26 | };
|
31 | 27 |
|
32 |
| - interval = mkOption { |
33 |
| - type = types.int; |
| 28 | + interval = lib.mkOption { |
| 29 | + type = lib.types.int; |
34 | 30 | default = if x == "liveness" then 30 else 2;
|
35 | 31 | description = "How often (in seconds) to perform the ${x} probe.";
|
36 | 32 | };
|
37 | 33 |
|
38 |
| - timeout = mkOption { |
39 |
| - type = types.int; |
| 34 | + timeout = lib.mkOption { |
| 35 | + type = lib.types.int; |
40 | 36 | default = 10;
|
41 | 37 | description = "Seconds after which the ${x} probe command times out.";
|
42 | 38 | };
|
43 |
| - retryCount = mkOption { |
44 |
| - type = types.int; |
| 39 | + retryCount = lib.mkOption { |
| 40 | + type = lib.types.int; |
45 | 41 | default = 10;
|
46 | 42 | description = "Number of times to retry the ${x} probe before considering it failed. (-1 means infinite retries)";
|
47 | 43 | };
|
48 | 44 | }
|
49 | 45 | // lib.optionalAttrs (x == "readiness") {
|
50 |
| - statusWaitingMessage = mkOption { |
51 |
| - type = types.str; |
| 46 | + statusWaitingMessage = lib.mkOption { |
| 47 | + type = lib.types.str; |
52 | 48 | default = "Service starting, waiting for ready signal...";
|
53 | 49 | description = "The status message to send to systemd while waiting.";
|
54 | 50 | };
|
55 | 51 |
|
56 |
| - statusReadyMessage = mkOption { |
57 |
| - type = types.str; |
| 52 | + statusReadyMessage = lib.mkOption { |
| 53 | + type = lib.types.str; |
58 | 54 | default = "Service is ready.";
|
59 | 55 | description = ''
|
60 | 56 | The status message to send when the service is ready.
|
|
84 | 80 | let
|
85 | 81 | cfg = serviceConfig.healthcheck;
|
86 | 82 | in
|
87 |
| - mkIf (cfg != null && cfg.readiness-probe.enable) { |
| 83 | + lib.mkIf (cfg != null && cfg.readiness-probe.enable) { |
88 | 84 | assertion = cfg.exec != null;
|
89 | 85 | message = "When healthcheck.readiness-probe is enabled, you must define `healthcheck.exec` with the service command. (${serviceName})";
|
90 | 86 | }
|
|
97 | 93 | in
|
98 | 94 | {
|
99 | 95 | name = "${mainServiceName}-liveness-check";
|
100 |
| - value = mkIf (cfg != null && cfg.liveness-probe.enable) { |
| 96 | + value = lib.mkIf (cfg != null && cfg.liveness-probe.enable) { |
101 | 97 | description = "Timer for ${mainServiceName} liveness probe";
|
102 | 98 | timerConfig = {
|
103 | 99 | Unit = "${mainServiceName}-liveness-check.service";
|
|
114 | 110 | let
|
115 | 111 | cfg = serviceConfig.healthcheck;
|
116 | 112 | in
|
117 |
| - (mkIf (cfg.readiness-probe.enable) ( |
| 113 | + (lib.mkIf (cfg.readiness-probe.enable) ( |
118 | 114 | let
|
119 | 115 | probeCfg = cfg.readiness-probe;
|
120 | 116 | in
|
|
127 | 123 | # We replace the ExecStart with a script that runs the readiness probe in the background, and the original service command in the foreground.
|
128 | 124 | serviceConfig.ExecStart =
|
129 | 125 | let
|
130 |
| - scriptPath = makeBinPath ( |
| 126 | + scriptPath = lib.makeBinPath ( |
131 | 127 | [
|
132 | 128 | pkgs.systemd
|
133 | 129 | pkgs.curl
|
|
187 | 183 | in
|
188 | 184 | {
|
189 | 185 | name = "${mainServiceName}-liveness-check";
|
190 |
| - value = mkIf (cfg != null && cfg.liveness-probe.enable) ( |
| 186 | + value = lib.mkIf (cfg != null && cfg.liveness-probe.enable) ( |
191 | 187 | let
|
192 | 188 | probeCfg = cfg.liveness-probe;
|
193 | 189 | checkScript = pkgs.writeShellScript "liveness-check" ''
|
|
230 | 226 | };
|
231 | 227 | };
|
232 | 228 |
|
233 |
| - options.mcl.services = mkOption { |
| 229 | + options.mcl.services = lib.mkOption { |
234 | 230 | default = { };
|
235 |
| - type = types.attrsOf ( |
236 |
| - types.submodule ( |
| 231 | + type = lib.types.attrsOf ( |
| 232 | + lib.types.submodule ( |
237 | 233 | { ... }:
|
238 | 234 | {
|
239 | 235 | options = {
|
240 |
| - healthcheck = mkOption { |
| 236 | + healthcheck = lib.mkOption { |
241 | 237 | default = null;
|
242 | 238 | description = "Declarative health checks for this systemd service.";
|
243 |
| - type = types.nullOr ( |
244 |
| - types.submodule { |
| 239 | + type = lib.types.nullOr ( |
| 240 | + lib.types.submodule { |
245 | 241 | options = {
|
246 | 242 | # Programs to add to the PATH for the health check.
|
247 |
| - runtimePackages = mkOption { |
248 |
| - type = types.listOf types.package; |
| 243 | + runtimePackages = lib.mkOption { |
| 244 | + type = lib.types.listOf lib.types.package; |
249 | 245 | default = [ ];
|
250 | 246 | description = "Additional programs to add to the PATH for health checks.";
|
251 | 247 | };
|
252 | 248 |
|
253 | 249 | # The main command for the service, required when readiness-probe is on.
|
254 |
| - exec = mkOption { |
255 |
| - type = types.str; |
| 250 | + exec = lib.mkOption { |
| 251 | + type = lib.types.str; |
256 | 252 | description = ''
|
257 | 253 | The actual command to run for the service.
|
258 | 254 | This MUST be used instead of `script` or `serviceConfig.ExecStart`
|
|
261 | 257 | };
|
262 | 258 |
|
263 | 259 | # The new readiness probe that uses the notify pattern.
|
264 |
| - readiness-probe = mkOption { |
265 |
| - type = types.submodule readinessProbeOptions; |
| 260 | + readiness-probe = lib.mkOption { |
| 261 | + type = lib.types.submodule readinessProbeOptions; |
266 | 262 | default = { };
|
267 | 263 | };
|
268 | 264 |
|
269 | 265 | # The liveness probe (timer-based).
|
270 |
| - liveness-probe = mkOption { |
271 |
| - type = types.submodule livenessProbeOptions; |
| 266 | + liveness-probe = lib.mkOption { |
| 267 | + type = lib.types.submodule livenessProbeOptions; |
272 | 268 | default = { };
|
273 | 269 | };
|
274 | 270 | };
|
|
0 commit comments