1{ pkgs, ... }:
2{
3 name = "mihomo";
4 meta.maintainers = with pkgs.lib.maintainers; [ Guanran928 ];
5
6 nodes.machine = {
7 environment.systemPackages = [ pkgs.curl ];
8
9 services.nginx = {
10 enable = true;
11 statusPage = true;
12 };
13
14 services.mihomo = {
15 enable = true;
16 configFile = pkgs.writeTextFile {
17 name = "config.yaml";
18 text = ''
19 mixed-port: 7890
20 external-controller: 127.0.0.1:9090
21 authentication:
22 - "user:supersecret"
23 '';
24 };
25 };
26 };
27
28 testScript = ''
29 # Wait until it starts
30 machine.wait_for_unit("nginx.service")
31 machine.wait_for_unit("mihomo.service")
32 machine.wait_for_open_port(80)
33 machine.wait_for_open_port(7890)
34 machine.wait_for_open_port(9090)
35
36 # Proxy
37 machine.succeed("curl --fail --max-time 10 --proxy http://user:supersecret@localhost:7890 http://localhost")
38 machine.succeed("curl --fail --max-time 10 --proxy socks5://user:supersecret@localhost:7890 http://localhost")
39 machine.fail("curl --fail --max-time 10 --proxy http://user:supervillain@localhost:7890 http://localhost")
40 machine.fail("curl --fail --max-time 10 --proxy socks5://user:supervillain@localhost:7890 http://localhost")
41
42 # Web UI
43 result = machine.succeed("curl --fail http://localhost:9090")
44 target = '{"hello":"mihomo"}\n'
45 assert result == target, f"{result!r} != {target!r}"
46 '';
47}