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 # Assert assets "geoip" and "geosite" are accessible.
54 {
55 type = "field";
56 ip = [ "geoip:private" ];
57 domain = [ "geosite:category-ads" ];
58 outboundTag = "direct";
59 }
60 ];
61 };
62
63in {
64 name = "v2ray";
65 meta = with lib.maintainers; {
66 maintainers = [ servalcatty ];
67 };
68 nodes.machine = { pkgs, ... }: {
69 environment.systemPackages = [ pkgs.curl ];
70 services.v2ray = {
71 enable = true;
72 config = v2rayConfig;
73 };
74 services.httpd = {
75 enable = true;
76 adminAddr = "foo@example.org";
77 };
78 };
79
80 testScript = ''
81 start_all()
82
83 machine.wait_for_unit("httpd.service")
84 machine.wait_for_unit("v2ray.service")
85 machine.wait_for_open_port(80)
86 machine.wait_for_open_port(1080)
87 machine.succeed(
88 "curl --fail --max-time 10 --proxy http://localhost:1080 http://localhost"
89 )
90 '';
91})