1import ./make-test-python.nix ({ lib, pkgs, ... }: let
2
3 v2rayUser = {
4 # A random UUID.
5 id = "a6a46834-2150-45f8-8364-0f6f6ab32384";
6 alterId = 0; # Non-zero support will be disabled in the future.
7 };
8
9 # 1080 [http proxy] -> 1081 [vmess] -> direct
10 v2rayConfig = {
11 inbounds = [
12 {
13 tag = "http_in";
14 port = 1080;
15 listen = "127.0.0.1";
16 protocol = "http";
17 }
18 {
19 tag = "vmess_in";
20 port = 1081;
21 listen = "127.0.0.1";
22 protocol = "vmess";
23 settings.clients = [v2rayUser];
24 }
25 ];
26 outbounds = [
27 {
28 tag = "vmess_out";
29 protocol = "vmess";
30 settings.vnext = [{
31 address = "127.0.0.1";
32 port = 1081;
33 users = [v2rayUser];
34 }];
35 }
36 {
37 tag = "direct";
38 protocol = "freedom";
39 }
40 ];
41 routing.rules = [
42 {
43 type = "field";
44 inboundTag = "http_in";
45 outboundTag = "vmess_out";
46 }
47 {
48 type = "field";
49 inboundTag = "vmess_in";
50 outboundTag = "direct";
51 }
52 ];
53 };
54
55in {
56 name = "v2ray";
57 meta = with lib.maintainers; {
58 maintainers = [ servalcatty ];
59 };
60 machine = { pkgs, ... }: {
61 environment.systemPackages = [ pkgs.curl ];
62 services.v2ray = {
63 enable = true;
64 config = v2rayConfig;
65 };
66 services.httpd = {
67 enable = true;
68 adminAddr = "foo@example.org";
69 };
70 };
71
72 testScript = ''
73 start_all()
74
75 machine.wait_for_unit("httpd.service")
76 machine.wait_for_unit("v2ray.service")
77 machine.wait_for_open_port(80)
78 machine.wait_for_open_port(1080)
79 machine.succeed(
80 "curl --fail --max-time 10 --proxy http://localhost:1080 http://localhost"
81 )
82 '';
83})