2020-06-12 08:12:51 +00:00
|
|
|
import ./make-test-python.nix (
|
|
|
|
{ lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
|
|
|
|
v2rayUser = {
|
|
|
|
# A random UUID.
|
|
|
|
id = "a6a46834-2150-45f8-8364-0f6f6ab32384";
|
2021-05-02 11:19:34 +00:00
|
|
|
alterId = 0; # Non-zero support will be disabled in the future.
|
2020-06-12 08:12:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
# 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";
|
2022-09-21 06:39:00 +00:00
|
|
|
settings.clients = [ v2rayUser ];
|
2020-06-12 08:12:51 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
outbounds = [
|
2024-12-10 19:26:33 +00:00
|
|
|
{
|
2020-06-12 08:12:51 +00:00
|
|
|
tag = "vmess_out";
|
|
|
|
protocol = "vmess";
|
|
|
|
settings.vnext = [
|
2024-12-10 19:26:33 +00:00
|
|
|
{
|
2020-06-12 08:12:51 +00:00
|
|
|
address = "127.0.0.1";
|
|
|
|
port = 1081;
|
2022-09-21 06:39:00 +00:00
|
|
|
users = [ v2rayUser ];
|
2020-06-12 08:12:51 +00:00
|
|
|
}
|
2024-12-10 19:26:33 +00:00
|
|
|
];
|
|
|
|
}
|
2020-06-12 08:12:51 +00:00
|
|
|
{
|
|
|
|
tag = "direct";
|
|
|
|
protocol = "freedom";
|
2024-12-10 19:26:33 +00:00
|
|
|
}
|
|
|
|
];
|
2020-06-12 08:12:51 +00:00
|
|
|
routing.rules = [
|
2024-12-10 19:26:33 +00:00
|
|
|
{
|
2020-06-12 08:12:51 +00:00
|
|
|
type = "field";
|
|
|
|
inboundTag = "http_in";
|
|
|
|
outboundTag = "vmess_out";
|
2024-12-10 19:26:33 +00:00
|
|
|
}
|
|
|
|
{
|
2020-06-12 08:12:51 +00:00
|
|
|
type = "field";
|
|
|
|
inboundTag = "vmess_in";
|
2022-09-21 06:39:00 +00:00
|
|
|
outboundTag = "direct";
|
|
|
|
}
|
2020-06-12 08:12:51 +00:00
|
|
|
|
2022-09-21 06:39:00 +00:00
|
|
|
# Assert assets "geoip" and "geosite" are accessible.
|
2020-06-12 08:12:51 +00:00
|
|
|
{
|
|
|
|
type = "field";
|
|
|
|
ip = [ "geoip:private" ];
|
|
|
|
domain = [ "geosite:category-ads" ];
|
|
|
|
outboundTag = "direct";
|
2024-12-10 19:26:33 +00:00
|
|
|
}
|
2020-06-12 08:12:51 +00:00
|
|
|
];
|
|
|
|
};
|
2024-12-10 19:26:33 +00:00
|
|
|
|
|
|
|
in
|
2020-06-12 08:12:51 +00:00
|
|
|
{
|
|
|
|
name = "v2ray";
|
|
|
|
meta = with lib.maintainers; {
|
|
|
|
maintainers = [ servalcatty ];
|
|
|
|
};
|
2022-03-20 23:15:30 +00:00
|
|
|
nodes.machine =
|
|
|
|
{ pkgs, ... }:
|
2024-12-10 19:26:33 +00:00
|
|
|
{
|
2020-06-12 08:12:51 +00:00
|
|
|
environment.systemPackages = [ pkgs.curl ];
|
|
|
|
services.v2ray = {
|
|
|
|
enable = true;
|
|
|
|
config = v2rayConfig;
|
|
|
|
};
|
|
|
|
services.httpd = {
|
|
|
|
enable = true;
|
|
|
|
adminAddr = "foo@example.org";
|
2024-12-10 19:26:33 +00:00
|
|
|
};
|
|
|
|
};
|
2020-06-12 08:12:51 +00:00
|
|
|
|
|
|
|
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"
|
|
|
|
)
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
)
|