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