1{ pkgs, lib, ... }:
2
3let
4 port = "1234";
5in
6{
7 name = "evcc";
8 meta.maintainers = with lib.maintainers; [ hexa ];
9
10 nodes = {
11 machine = {
12 services.evcc = {
13 enable = true;
14 # This is NOT a safe way to deal with secrets in production
15 environmentFile = pkgs.writeText "evcc-secrets" ''
16 PORT=${toString port}
17 '';
18 settings = {
19 network = {
20 schema = "http";
21 host = "localhost";
22 port = "$PORT";
23 };
24
25 log = "info";
26
27 site = {
28 title = "NixOS Test";
29 meters = {
30 grid = "grid";
31 pv = "pv";
32 };
33 };
34
35 meters = [
36 {
37 type = "custom";
38 name = "grid";
39 power = {
40 source = "script";
41 cmd = "/bin/sh -c 'echo -4500'";
42 };
43 }
44 {
45 type = "custom";
46 name = "pv";
47 power = {
48 source = "script";
49 cmd = "/bin/sh -c 'echo 7500'";
50 };
51 }
52 ];
53
54 chargers = [
55 {
56 name = "dummy-charger";
57 type = "custom";
58 status = {
59 source = "script";
60 cmd = "/bin/sh -c 'echo A'";
61 };
62 enabled = {
63 source = "script";
64 cmd = "/bin/sh -c 'echo false'";
65 };
66 enable = {
67 source = "script";
68 cmd = "/bin/sh -c 'echo true'";
69 };
70 maxcurrent = {
71 source = "script";
72 cmd = "/bin/sh -c 'echo 7200'";
73 };
74 }
75 ];
76
77 loadpoints = [
78 {
79 title = "Dummy";
80 charger = "dummy-charger";
81 }
82 ];
83 };
84 };
85 };
86 };
87
88 testScript = ''
89 start_all()
90
91 machine.wait_for_unit("evcc.service")
92 machine.wait_for_open_port(${port})
93
94 with subtest("Check package version propagates into frontend"):
95 machine.fail(
96 "curl --fail http://localhost:${port} | grep '0.0.1-alpha'"
97 )
98 machine.succeed(
99 "curl --fail http://localhost:${port} | grep '${pkgs.evcc.version}'"
100 )
101
102 with subtest("Check journal for errors"):
103 _, output = machine.execute("journalctl -o cat -u evcc.service")
104 assert "FATAL" not in output
105
106 with subtest("Check systemd hardening"):
107 _, output = machine.execute("systemd-analyze security evcc.service | grep -v '✓'")
108 machine.log(output)
109 '';
110}