1{ lib, pkgs, ... }:
2{
3 name = "healthchecks";
4
5 meta = with lib.maintainers; {
6 maintainers = [ phaer ];
7 };
8
9 nodes.machine =
10 { ... }:
11 {
12 services.healthchecks = {
13 enable = true;
14 settings = {
15 SITE_NAME = "MyUniqueInstance";
16 COMPRESS_ENABLED = "True";
17 SECRET_KEY_FILE = pkgs.writeText "secret" "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
18 };
19 };
20 };
21
22 testScript = ''
23 machine.start()
24 machine.wait_for_unit("healthchecks.target")
25 machine.wait_until_succeeds("journalctl --since -1m --unit healthchecks --grep Listening")
26
27 with subtest("Home screen loads"):
28 machine.succeed(
29 "curl -sSfL http://localhost:8000 | grep '<title>Log In'"
30 )
31
32 with subtest("Setting SITE_NAME via freeform option works"):
33 machine.succeed(
34 "curl -sSfL http://localhost:8000 | grep 'MyUniqueInstance</title>'"
35 )
36
37 with subtest("Manage script works"):
38 # "shell" sucommand should succeed, needs python in PATH.
39 t.assertIn(
40 "\nfoo\n",
41 machine.succeed("echo 'print(\"foo\")' | sudo -u healthchecks healthchecks-manage shell")
42 )
43 # Shouldn't fail if not called by healthchecks user
44 t.assertIn(
45 "\nfoo\n",
46 machine.succeed("echo 'print(\"foo\")' | healthchecks-manage shell")
47 )
48 '';
49}