Skip to content

Commit c390be9

Browse files
committed
wip
1 parent 5835b51 commit c390be9

File tree

1 file changed

+34
-38
lines changed

1 file changed

+34
-38
lines changed

modules/healthcheck/default.nix

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,49 @@
88
pkgs,
99
...
1010
}:
11-
12-
with lib;
13-
1411
let
15-
1612
mkProbeOptions = x: {
1713
options =
1814
{
19-
enable = mkEnableOption "the ${x} probe";
15+
enable = lib.mkEnableOption "the ${x} probe";
2016

21-
command = mkOption {
22-
type = types.str;
17+
command = lib.mkOption {
18+
type = lib.types.str;
2319
description = "The command to execute for the ${x} check. Any necessary programs should be added to the healthcheck.runtimePackages option.";
2420
};
2521

26-
initialDelay = mkOption {
27-
type = types.int;
22+
initialDelay = lib.mkOption {
23+
type = lib.types.int;
2824
default = 15;
2925
description = "Seconds to wait after the service is up before the first ${x} probe.";
3026
};
3127

32-
interval = mkOption {
33-
type = types.int;
28+
interval = lib.mkOption {
29+
type = lib.types.int;
3430
default = if x == "liveness" then 30 else 2;
3531
description = "How often (in seconds) to perform the ${x} probe.";
3632
};
3733

38-
timeout = mkOption {
39-
type = types.int;
34+
timeout = lib.mkOption {
35+
type = lib.types.int;
4036
default = 10;
4137
description = "Seconds after which the ${x} probe command times out.";
4238
};
43-
retryCount = mkOption {
44-
type = types.int;
39+
retryCount = lib.mkOption {
40+
type = lib.types.int;
4541
default = 10;
4642
description = "Number of times to retry the ${x} probe before considering it failed. (-1 means infinite retries)";
4743
};
4844
}
4945
// lib.optionalAttrs (x == "readiness") {
50-
statusWaitingMessage = mkOption {
51-
type = types.str;
46+
statusWaitingMessage = lib.mkOption {
47+
type = lib.types.str;
5248
default = "Service starting, waiting for ready signal...";
5349
description = "The status message to send to systemd while waiting.";
5450
};
5551

56-
statusReadyMessage = mkOption {
57-
type = types.str;
52+
statusReadyMessage = lib.mkOption {
53+
type = lib.types.str;
5854
default = "Service is ready.";
5955
description = ''
6056
The status message to send when the service is ready.
@@ -84,7 +80,7 @@
8480
let
8581
cfg = serviceConfig.healthcheck;
8682
in
87-
mkIf (cfg != null && cfg.readiness-probe.enable) {
83+
lib.mkIf (cfg != null && cfg.readiness-probe.enable) {
8884
assertion = cfg.exec != null;
8985
message = "When healthcheck.readiness-probe is enabled, you must define `healthcheck.exec` with the service command. (${serviceName})";
9086
}
@@ -97,7 +93,7 @@
9793
in
9894
{
9995
name = "${mainServiceName}-liveness-check";
100-
value = mkIf (cfg != null && cfg.liveness-probe.enable) {
96+
value = lib.mkIf (cfg != null && cfg.liveness-probe.enable) {
10197
description = "Timer for ${mainServiceName} liveness probe";
10298
timerConfig = {
10399
Unit = "${mainServiceName}-liveness-check.service";
@@ -114,7 +110,7 @@
114110
let
115111
cfg = serviceConfig.healthcheck;
116112
in
117-
(mkIf (cfg.readiness-probe.enable) (
113+
(lib.mkIf (cfg.readiness-probe.enable) (
118114
let
119115
probeCfg = cfg.readiness-probe;
120116
in
@@ -127,7 +123,7 @@
127123
# We replace the ExecStart with a script that runs the readiness probe in the background, and the original service command in the foreground.
128124
serviceConfig.ExecStart =
129125
let
130-
scriptPath = makeBinPath (
126+
scriptPath = lib.makeBinPath (
131127
[
132128
pkgs.systemd
133129
pkgs.curl
@@ -187,7 +183,7 @@
187183
in
188184
{
189185
name = "${mainServiceName}-liveness-check";
190-
value = mkIf (cfg != null && cfg.liveness-probe.enable) (
186+
value = lib.mkIf (cfg != null && cfg.liveness-probe.enable) (
191187
let
192188
probeCfg = cfg.liveness-probe;
193189
checkScript = pkgs.writeShellScript "liveness-check" ''
@@ -230,29 +226,29 @@
230226
};
231227
};
232228

233-
options.mcl.services = mkOption {
229+
options.mcl.services = lib.mkOption {
234230
default = { };
235-
type = types.attrsOf (
236-
types.submodule (
231+
type = lib.types.attrsOf (
232+
lib.types.submodule (
237233
{ ... }:
238234
{
239235
options = {
240-
healthcheck = mkOption {
236+
healthcheck = lib.mkOption {
241237
default = null;
242238
description = "Declarative health checks for this systemd service.";
243-
type = types.nullOr (
244-
types.submodule {
239+
type = lib.types.nullOr (
240+
lib.types.submodule {
245241
options = {
246242
# 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;
249245
default = [ ];
250246
description = "Additional programs to add to the PATH for health checks.";
251247
};
252248

253249
# 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;
256252
description = ''
257253
The actual command to run for the service.
258254
This MUST be used instead of `script` or `serviceConfig.ExecStart`
@@ -261,14 +257,14 @@
261257
};
262258

263259
# 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;
266262
default = { };
267263
};
268264

269265
# 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;
272268
default = { };
273269
};
274270
};

0 commit comments

Comments
 (0)