1import ./make-test-python.nix ({ lib, pkgs, ... }: {
2
3 name = "sing-box";
4
5 meta = {
6 maintainers = with lib.maintainers; [ nickcao ];
7 };
8
9 nodes.machine = { pkgs, ... }: {
10 environment.systemPackages = [ pkgs.curl ];
11 services.nginx = {
12 enable = true;
13 statusPage = true;
14 };
15 services.sing-box = {
16 enable = true;
17 settings = {
18 inbounds = [{
19 type = "mixed";
20 tag = "inbound";
21 listen = "127.0.0.1";
22 listen_port = 1080;
23 users = [{
24 username = "user";
25 password = { _secret = pkgs.writeText "password" "supersecret"; };
26 }];
27 }];
28 outbounds = [{
29 type = "direct";
30 tag = "outbound";
31 }];
32 };
33 };
34 };
35
36 testScript = ''
37 machine.wait_for_unit("nginx.service")
38 machine.wait_for_unit("sing-box.service")
39
40 machine.wait_for_open_port(80)
41 machine.wait_for_open_port(1080)
42
43 machine.succeed("curl --fail --max-time 10 --proxy http://user:supersecret@localhost:1080 http://localhost")
44 machine.fail("curl --fail --max-time 10 --proxy http://user:supervillain@localhost:1080 http://localhost")
45 machine.succeed("curl --fail --max-time 10 --proxy socks5://user:supersecret@localhost:1080 http://localhost")
46 '';
47
48})