git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #96958 from servalcatty/v2ray

v2ray: 4.26.0 -> 4.27.5 and add tests

commit61525137fd1002f6f2a5eb0ea27d480713362cd5 authorRobert Scott <code@humanleg.org.uk> dateMon 7 Sep 2020, 21:29 (6 years ago) parentb44c531312e17b
4 files changed+146−63
nixos/tests/all-tests.nix+1 nixos/tests/v2ray.nix+83 pkgs/tools/networking/v2ray/default.nix+62−11 pkgs/tools/networking/v2ray/generic.nix−52
nixos/tests/all-tests.nix+1
@@ -363,6 +363,7 @@ in
363363 unit-php = handleTest ./web-servers/unit-php.nix {};
364364 upnp = handleTest ./upnp.nix {};
365365 uwsgi = handleTest ./uwsgi.nix {};
366+ v2ray = handleTest ./v2ray.nix {};
366367 vault = handleTest ./vault.nix {};
367368 victoriametrics = handleTest ./victoriametrics.nix {};
368369 virtualbox = handleTestOn ["x86_64-linux"] ./virtualbox.nix {};
nixos/tests/v2ray.nixnew file+83
@@ -0,0 +1,83 @@
1+import ./make-test-python.nix ({ lib, pkgs, ... }: let
2+
3+ v2rayUser = {
4+ # A random UUID.
5+ id = "a6a46834-2150-45f8-8364-0f6f6ab32384";
6+ alterId = 4;
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+ };
54+
55+in {
56+ name = "v2ray";
57+ meta = with lib.maintainers; {
58+ maintainers = [ servalcatty ];
59+ };
60+ machine = { pkgs, ... }: {
61+ environment.systemPackages = [ pkgs.curl ];
62+ services.v2ray = {
63+ enable = true;
64+ config = v2rayConfig;
65+ };
66+ services.httpd = {
67+ enable = true;
68+ adminAddr = "foo@example.org";
69+ };
70+ };
71+
72+ testScript = ''
73+ start_all()
74+
75+ machine.wait_for_unit("httpd.service")
76+ machine.wait_for_unit("v2ray.service")
77+ machine.wait_for_open_port(80)
78+ machine.wait_for_open_port(1080)
79+ machine.succeed(
80+ "curl --fail --max-time 10 --proxy http://localhost:1080 http://localhost"
81+ )
82+ '';
83+})
pkgs/tools/networking/v2ray/default.nix+62−11
@@ -1,24 +1,24 @@
1−{ callPackage, fetchFromGitHub, fetchurl
1+{ lib, fetchFromGitHub, fetchurl, linkFarm, buildGoModule, runCommand, makeWrapper, nixosTests
22, assetOverrides ? {}
3−, ... } @ args:
3+}:
44
5−callPackage ./generic.nix (rec {
6− version = "4.26.0";
5+let
6+ version = "4.27.5";
77
88 src = fetchFromGitHub {
99 owner = "v2ray";
1010 repo = "v2ray-core";
1111 rev = "v${version}";
12− sha256 = "069wm0n44i4l9pnrhwf60ssld65p6gfj4wfc68hrhj4zi4jvlyds";
12+ sha256 = "168kz8hq7mcfy6h758mmrky550p04bi9jsfqhy67jcxq81874m2k";
1313 };
1414
15− vendorSha256 = "1520h69z0inbsrw5505cxbinqakvwcrdx3pisrwnp9lv4jsrzzsr";
15+ vendorSha256 = "0m889byxw70vv1mzlivalq444byp0y182nqqzdr458gfifvpc7s7";
1616
1717 assets = {
1818 # MIT licensed
1919 "geoip.dat" = let
20− geoipRev = "202007080004";
21− geoipSha256 = "1j4qg831dhxdy7brgxn4ca69cvwr3zsgizidlzasbkdn2rwai17y";
20+ geoipRev = "202009020005";
21+ geoipSha256 = "1xsy678cpqv6ycnhzl3pms76ic40aggq46q9dsd5ghj94mcx9837";
2222 in fetchurl {
2323 url = "https://github.com/v2ray/geoip/releases/download/${geoipRev}/geoip.dat";
2424 sha256 = geoipSha256;
@@ -26,8 +26,8 @@ callPackage ./generic.nix (rec {
2626
2727 # MIT licensed
2828 "geosite.dat" = let
29− geositeRev = "20200708125309";
30− geositeSha256 = "1pr4137ri3v3r880yx5sqf2p7qfn8g7s555q51x3smkjzkyrskcy";
29+ geositeRev = "20200901194123";
30+ geositeSha256 = "0fjx1wrq14d9v326k4fjwca3h5nv8ghk11kprf6jkjncjszwvgby";
3131 in fetchurl {
3232 url = "https://github.com/v2ray/domain-list-community/releases/download/${geositeRev}/dlc.dat";
3333 sha256 = geositeSha256;
@@ -35,4 +35,55 @@ callPackage ./generic.nix (rec {
3535
3636 } // assetOverrides;
3737
38−} // args)
38+ assetsDrv = linkFarm "v2ray-assets" (lib.mapAttrsToList (name: path: {
39+ inherit name path;
40+ }) assets);
41+
42+ core = buildGoModule rec {
43+ pname = "v2ray-core";
44+ inherit version src;
45+
46+ inherit vendorSha256;
47+
48+ doCheck = false;
49+
50+ buildPhase = ''
51+ runHook preBuild
52+
53+ go build -o v2ray v2ray.com/core/main
54+ go build -o v2ctl v2ray.com/core/infra/control/main
55+
56+ runHook postBuild
57+ '';
58+
59+ installPhase = ''
60+ install -Dm755 v2ray v2ctl -t $out/bin
61+ '';
62+ };
63+
64+in runCommand "v2ray-${version}" {
65+ inherit version;
66+
67+ buildInputs = [ assetsDrv core ];
68+ nativeBuildInputs = [ makeWrapper ];
69+
70+ meta = {
71+ homepage = "https://www.v2ray.com/en/index.html";
72+ description = "A platform for building proxies to bypass network restrictions";
73+ license = with lib.licenses; [ mit ];
74+ maintainers = with lib.maintainers; [ servalcatty ];
75+ };
76+
77+ passthru = {
78+ updateScript = ./update.sh;
79+ tests = {
80+ simple-vmess-proxy-test = nixosTests.v2ray;
81+ };
82+ };
83+
84+} ''
85+ for file in ${core}/bin/*; do
86+ makeWrapper "$file" "$out/bin/$(basename "$file")" \
87+ --set-default V2RAY_LOCATION_ASSET ${assetsDrv}
88+ done
89+''
pkgs/tools/networking/v2ray/generic.nixdeleted−52
@@ -1,52 +0,0 @@
1−{ lib, linkFarm, buildGoModule, runCommand, makeWrapper
2−
3−# Version specific args
4−, version, src, assets, vendorSha256
5−, ... }:
6−
7−let
8− assetsDrv = linkFarm "v2ray-assets" (lib.mapAttrsToList (name: path: {
9− inherit name path;
10− }) assets);
11−
12− core = buildGoModule rec {
13− pname = "v2ray-core";
14− inherit version src;
15−
16− inherit vendorSha256;
17−
18− doCheck = false;
19−
20− buildPhase = ''
21− runHook preBuild
22−
23− go build -o v2ray v2ray.com/core/main
24− go build -o v2ctl v2ray.com/core/infra/control/main
25−
26− runHook postBuild
27− '';
28−
29− installPhase = ''
30− install -Dm755 v2ray v2ctl -t $out/bin
31− '';
32− };
33−
34−in runCommand "v2ray-${version}" {
35− inherit version;
36−
37− buildInputs = [ assetsDrv core ];
38− nativeBuildInputs = [ makeWrapper ];
39−
40− meta = {
41− homepage = "https://www.v2ray.com/en/index.html";
42− description = "A platform for building proxies to bypass network restrictions";
43− license = with lib.licenses; [ mit ];
44− maintainers = with lib.maintainers; [ servalcatty ];
45− };
46−
47−} ''
48− for file in ${core}/bin/*; do
49− makeWrapper "$file" "$out/bin/$(basename "$file")" \
50− --set-default V2RAY_LOCATION_ASSET ${assetsDrv}
51− done
52−''