From 9a5a8949aa415bd49312e42610d0c3e07f5d581e Mon Sep 17 00:00:00 2001 From: Serval Date: Wed, 2 Sep 2020 22:13:02 +0800 Subject: [PATCH 1/4] v2ray: 4.26.0 -> 4.27.5 --- pkgs/tools/networking/v2ray/default.nix | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkgs/tools/networking/v2ray/default.nix b/pkgs/tools/networking/v2ray/default.nix index ab3f5eb3ef4..d362810b56c 100644 --- a/pkgs/tools/networking/v2ray/default.nix +++ b/pkgs/tools/networking/v2ray/default.nix @@ -3,22 +3,22 @@ , ... } @ args: callPackage ./generic.nix (rec { - version = "4.26.0"; + version = "4.27.5"; src = fetchFromGitHub { owner = "v2ray"; repo = "v2ray-core"; rev = "v${version}"; - sha256 = "069wm0n44i4l9pnrhwf60ssld65p6gfj4wfc68hrhj4zi4jvlyds"; + sha256 = "168kz8hq7mcfy6h758mmrky550p04bi9jsfqhy67jcxq81874m2k"; }; - vendorSha256 = "1520h69z0inbsrw5505cxbinqakvwcrdx3pisrwnp9lv4jsrzzsr"; + vendorSha256 = "0m889byxw70vv1mzlivalq444byp0y182nqqzdr458gfifvpc7s7"; assets = { # MIT licensed "geoip.dat" = let - geoipRev = "202007080004"; - geoipSha256 = "1j4qg831dhxdy7brgxn4ca69cvwr3zsgizidlzasbkdn2rwai17y"; + geoipRev = "202009020005"; + geoipSha256 = "1xsy678cpqv6ycnhzl3pms76ic40aggq46q9dsd5ghj94mcx9837"; in fetchurl { url = "https://github.com/v2ray/geoip/releases/download/${geoipRev}/geoip.dat"; sha256 = geoipSha256; @@ -26,8 +26,8 @@ callPackage ./generic.nix (rec { # MIT licensed "geosite.dat" = let - geositeRev = "20200708125309"; - geositeSha256 = "1pr4137ri3v3r880yx5sqf2p7qfn8g7s555q51x3smkjzkyrskcy"; + geositeRev = "20200901194123"; + geositeSha256 = "0fjx1wrq14d9v326k4fjwca3h5nv8ghk11kprf6jkjncjszwvgby"; in fetchurl { url = "https://github.com/v2ray/domain-list-community/releases/download/${geositeRev}/dlc.dat"; sha256 = geositeSha256; From 4ac99e76bc032c0fa85491165a078f541c283b05 Mon Sep 17 00:00:00 2001 From: Serval Date: Fri, 12 Jun 2020 16:12:51 +0800 Subject: [PATCH 2/4] nixos/tests/v2ray: init --- nixos/tests/all-tests.nix | 1 + nixos/tests/v2ray.nix | 83 +++++++++++++++++++++++++ pkgs/tools/networking/v2ray/generic.nix | 6 +- 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 nixos/tests/v2ray.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 60ef5a02763..fa03e2506e8 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -362,6 +362,7 @@ in unit-php = handleTest ./web-servers/unit-php.nix {}; upnp = handleTest ./upnp.nix {}; uwsgi = handleTest ./uwsgi.nix {}; + v2ray = handleTest ./v2ray.nix {}; vault = handleTest ./vault.nix {}; victoriametrics = handleTest ./victoriametrics.nix {}; virtualbox = handleTestOn ["x86_64-linux"] ./virtualbox.nix {}; 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" + ) + ''; +}) diff --git a/pkgs/tools/networking/v2ray/generic.nix b/pkgs/tools/networking/v2ray/generic.nix index 4499e91425f..04ac482e898 100644 --- a/pkgs/tools/networking/v2ray/generic.nix +++ b/pkgs/tools/networking/v2ray/generic.nix @@ -1,4 +1,4 @@ -{ lib, linkFarm, buildGoModule, runCommand, makeWrapper +{ lib, linkFarm, buildGoModule, runCommand, makeWrapper, nixosTests # Version specific args , version, src, assets, vendorSha256 @@ -44,6 +44,10 @@ in runCommand "v2ray-${version}" { maintainers = with lib.maintainers; [ servalcatty ]; }; + passthru.tests = { + simple-vmess-proxy-test = nixosTests.v2ray; + }; + } '' for file in ${core}/bin/*; do makeWrapper "$file" "$out/bin/$(basename "$file")" \ From 32940aeec4c1c25d63bc9c75c22ee92dd05283c4 Mon Sep 17 00:00:00 2001 From: Serval Date: Tue, 8 Sep 2020 03:23:12 +0800 Subject: [PATCH 3/4] v2ray: simplify nix --- pkgs/tools/networking/v2ray/default.nix | 59 +++++++++++++++++++++++-- pkgs/tools/networking/v2ray/generic.nix | 56 ----------------------- 2 files changed, 55 insertions(+), 60 deletions(-) delete mode 100644 pkgs/tools/networking/v2ray/generic.nix diff --git a/pkgs/tools/networking/v2ray/default.nix b/pkgs/tools/networking/v2ray/default.nix index d362810b56c..183156036aa 100644 --- a/pkgs/tools/networking/v2ray/default.nix +++ b/pkgs/tools/networking/v2ray/default.nix @@ -1,8 +1,8 @@ -{ callPackage, fetchFromGitHub, fetchurl +{ lib, fetchFromGitHub, fetchurl, linkFarm, buildGoModule, runCommand, makeWrapper, nixosTests , assetOverrides ? {} -, ... } @ args: +}: -callPackage ./generic.nix (rec { +let version = "4.27.5"; src = fetchFromGitHub { @@ -35,4 +35,55 @@ callPackage ./generic.nix (rec { } // assetOverrides; -} // args) + 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 ]; + }; + + passthru = { + updateScript = ./update.sh; + tests = { + simple-vmess-proxy-test = nixosTests.v2ray; + }; + }; + +} '' + for file in ${core}/bin/*; do + makeWrapper "$file" "$out/bin/$(basename "$file")" \ + --set-default V2RAY_LOCATION_ASSET ${assetsDrv} + done +'' \ No newline at end of file diff --git a/pkgs/tools/networking/v2ray/generic.nix b/pkgs/tools/networking/v2ray/generic.nix deleted file mode 100644 index 04ac482e898..00000000000 --- a/pkgs/tools/networking/v2ray/generic.nix +++ /dev/null @@ -1,56 +0,0 @@ -{ lib, linkFarm, buildGoModule, runCommand, makeWrapper, nixosTests - -# 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 ]; - }; - - passthru.tests = { - simple-vmess-proxy-test = nixosTests.v2ray; - }; - -} '' - for file in ${core}/bin/*; do - makeWrapper "$file" "$out/bin/$(basename "$file")" \ - --set-default V2RAY_LOCATION_ASSET ${assetsDrv} - done -'' From 312e17b3299612834db46ef988a0fe0722a57516 Mon Sep 17 00:00:00 2001 From: Serval Date: Tue, 8 Sep 2020 03:35:26 +0800 Subject: [PATCH 4/4] v2ray: fix newline --- pkgs/tools/networking/v2ray/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/tools/networking/v2ray/default.nix b/pkgs/tools/networking/v2ray/default.nix index 183156036aa..bc8a0873f78 100644 --- a/pkgs/tools/networking/v2ray/default.nix +++ b/pkgs/tools/networking/v2ray/default.nix @@ -86,4 +86,4 @@ in runCommand "v2ray-${version}" { makeWrapper "$file" "$out/bin/$(basename "$file")" \ --set-default V2RAY_LOCATION_ASSET ${assetsDrv} done -'' \ No newline at end of file +''