commit
61525137fd
@ -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" |
||||
) |
||||
''; |
||||
}) |
@ -1,52 +0,0 @@ |
||||
{ lib, linkFarm, buildGoModule, runCommand, makeWrapper |
||||
|
||||
# Version specific args |
||||
, version, src, assets, vendorSha256 |
||||
, ... }: |
||||
|
||||
let |
||||
assetsDrv = linkFarm "v2ray-assets" (lib.mapAttrsToList (name: path: { |
||||
inherit name path; |
||||
}) assets); |
||||
|
||||
core = buildGoModule rec { |
||||
pname = "v2ray-core"; |
||||
inherit version src; |
||||
|
||||
inherit vendorSha256; |
||||
|
||||
doCheck = false; |
||||
|
||||
buildPhase = '' |
||||
runHook preBuild |
||||
|
||||
go build -o v2ray v2ray.com/core/main |
||||
go build -o v2ctl v2ray.com/core/infra/control/main |
||||
|
||||
runHook postBuild |
||||
''; |
||||
|
||||
installPhase = '' |
||||
install -Dm755 v2ray v2ctl -t $out/bin |
||||
''; |
||||
}; |
||||
|
||||
in runCommand "v2ray-${version}" { |
||||
inherit version; |
||||
|
||||
buildInputs = [ assetsDrv core ]; |
||||
nativeBuildInputs = [ makeWrapper ]; |
||||
|
||||
meta = { |
||||
homepage = "https://www.v2ray.com/en/index.html"; |
||||
description = "A platform for building proxies to bypass network restrictions"; |
||||
license = with lib.licenses; [ mit ]; |
||||
maintainers = with lib.maintainers; [ servalcatty ]; |
||||
}; |
||||
|
||||
} '' |
||||
for file in ${core}/bin/*; do |
||||
makeWrapper "$file" "$out/bin/$(basename "$file")" \ |
||||
--set-default V2RAY_LOCATION_ASSET ${assetsDrv} |
||||
done |
||||
'' |
Loading…
Reference in new issue