diff options
author | Serval <servalcat@pm.me> | 2020-06-12 16:12:51 +0800 |
---|---|---|
committer | Serval <servalcat@pm.me> | 2020-09-02 22:18:52 +0800 |
commit | 4ac99e76bc032c0fa85491165a078f541c283b05 (patch) | |
tree | 91174f322b201deefefc577b0d1c4a610b972927 /nixos/tests/v2ray.nix | |
parent | 9a5a8949aa415bd49312e42610d0c3e07f5d581e (diff) | |
download | nixpkgs-4ac99e76bc032c0fa85491165a078f541c283b05.tar nixpkgs-4ac99e76bc032c0fa85491165a078f541c283b05.tar.gz nixpkgs-4ac99e76bc032c0fa85491165a078f541c283b05.tar.bz2 nixpkgs-4ac99e76bc032c0fa85491165a078f541c283b05.tar.lz nixpkgs-4ac99e76bc032c0fa85491165a078f541c283b05.tar.xz nixpkgs-4ac99e76bc032c0fa85491165a078f541c283b05.tar.zst nixpkgs-4ac99e76bc032c0fa85491165a078f541c283b05.zip |
nixos/tests/v2ray: init
Diffstat (limited to 'nixos/tests/v2ray.nix')
-rw-r--r-- | nixos/tests/v2ray.nix | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/nixos/tests/v2ray.nix b/nixos/tests/v2ray.nix new file mode 100644 index 00000000000..f1b2570cc86 --- /dev/null +++ b/nixos/tests/v2ray.nix @@ -0,0 +1,83 @@ +import ./make-test-python.nix ({ lib, pkgs, ... }: let + + v2rayUser = { + # A random UUID. + id = "a6a46834-2150-45f8-8364-0f6f6ab32384"; + alterId = 4; + }; + + # 1080 [http proxy] -> 1081 [vmess] -> direct + v2rayConfig = { + inbounds = [ + { + tag = "http_in"; + port = 1080; + listen = "127.0.0.1"; + protocol = "http"; + } + { + tag = "vmess_in"; + port = 1081; + listen = "127.0.0.1"; + protocol = "vmess"; + settings.clients = [v2rayUser]; + } + ]; + outbounds = [ + { + tag = "vmess_out"; + protocol = "vmess"; + settings.vnext = [{ + address = "127.0.0.1"; + port = 1081; + users = [v2rayUser]; + }]; + } + { + tag = "direct"; + protocol = "freedom"; + } + ]; + routing.rules = [ + { + type = "field"; + inboundTag = "http_in"; + outboundTag = "vmess_out"; + } + { + type = "field"; + inboundTag = "vmess_in"; + outboundTag = "direct"; + } + ]; + }; + +in { + name = "v2ray"; + meta = with lib.maintainers; { + maintainers = [ servalcatty ]; + }; + machine = { pkgs, ... }: { + environment.systemPackages = [ pkgs.curl ]; + services.v2ray = { + enable = true; + config = v2rayConfig; + }; + services.httpd = { + enable = true; + adminAddr = "foo@example.org"; + }; + }; + + testScript = '' + start_all() + + machine.wait_for_unit("httpd.service") + machine.wait_for_unit("v2ray.service") + machine.wait_for_open_port(80) + machine.wait_for_open_port(1080) + machine.succeed( + "curl --fail --max-time 10 --proxy http://localhost:1080 http://localhost" + ) + ''; +}) |