lol
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #192196 from oxalica/pkg/v2ray

v2ray: 4.45.0 -> 5.1.0 and refactor

authored by

Mario Rodas and committed by
GitHub
0ea721a9 98110a38

+64 -109
+10 -8
nixos/modules/services/networking/v2ray.nix
··· 34 34 35 35 Either `configFile` or `config` must be specified. 36 36 37 - See <https://www.v2fly.org/en_US/config/overview.html>. 37 + See <https://www.v2fly.org/en_US/v5/config/overview.html>. 38 38 ''; 39 39 }; 40 40 ··· 56 56 57 57 Either `configFile` or `config` must be specified. 58 58 59 - See <https://www.v2fly.org/en_US/config/overview.html>. 59 + See <https://www.v2fly.org/en_US/v5/config/overview.html>. 60 60 ''; 61 61 }; 62 62 }; ··· 71 71 name = "v2ray.json"; 72 72 text = builtins.toJSON cfg.config; 73 73 checkPhase = '' 74 - ${cfg.package}/bin/v2ray -test -config $out 74 + ${cfg.package}/bin/v2ray test -c $out 75 75 ''; 76 76 }; 77 77 ··· 83 83 } 84 84 ]; 85 85 86 + environment.etc."v2ray/config.json".source = configFile; 87 + 88 + systemd.packages = [ cfg.package ]; 89 + 86 90 systemd.services.v2ray = { 87 - description = "v2ray Daemon"; 88 - after = [ "network.target" ]; 91 + restartTriggers = [ config.environment.etc."v2ray/config.json".source ]; 92 + 93 + # Workaround: https://github.com/NixOS/nixpkgs/issues/81138 89 94 wantedBy = [ "multi-user.target" ]; 90 - serviceConfig = { 91 - ExecStart = "${cfg.package}/bin/v2ray -config ${configFile}"; 92 - }; 93 95 }; 94 96 }; 95 97 }
+10 -2
nixos/tests/v2ray.nix
··· 20 20 port = 1081; 21 21 listen = "127.0.0.1"; 22 22 protocol = "vmess"; 23 - settings.clients = [v2rayUser]; 23 + settings.clients = [ v2rayUser ]; 24 24 } 25 25 ]; 26 26 outbounds = [ ··· 30 30 settings.vnext = [{ 31 31 address = "127.0.0.1"; 32 32 port = 1081; 33 - users = [v2rayUser]; 33 + users = [ v2rayUser ]; 34 34 }]; 35 35 } 36 36 { ··· 47 47 { 48 48 type = "field"; 49 49 inboundTag = "vmess_in"; 50 + outboundTag = "direct"; 51 + } 52 + 53 + # Assert assets "geoip" and "geosite" are accessible. 54 + { 55 + type = "field"; 56 + ip = [ "geoip:private" ]; 57 + domain = [ "geosite:category-ads" ]; 50 58 outboundTag = "direct"; 51 59 } 52 60 ];
+2 -2
pkgs/data/misc/v2ray-domain-list-community/default.nix
··· 3 3 let 4 4 generator = pkgsBuildBuild.buildGoModule rec { 5 5 pname = "v2ray-domain-list-community"; 6 - version = "20220908131416"; 6 + version = "20220921050909"; 7 7 src = fetchFromGitHub { 8 8 owner = "v2fly"; 9 9 repo = "domain-list-community"; 10 10 rev = version; 11 - sha256 = "sha256-LXtdyLINmUcyT2x9w7KCoLLifcYrSq6JN+2J9wbKjCI="; 11 + sha256 = "sha256-ujslsVqUQ16LFdCwwKmY2SnoqNTRenI5cEreupt/6c4="; 12 12 }; 13 13 vendorSha256 = "sha256-CCY3CgjA1w4svzmkaI2Jt272Rrt5UOt5sbVDAWRRfzk="; 14 14 meta = with lib; {
+42 -48
pkgs/tools/networking/v2ray/default.nix
··· 1 - { lib, fetchFromGitHub, fetchurl, symlinkJoin, buildGoModule, runCommand, makeWrapper, nixosTests 2 - , v2ray-geoip, v2ray-domain-list-community, assets ? [ v2ray-geoip v2ray-domain-list-community ] 1 + { lib, fetchFromGitHub, symlinkJoin, buildGoModule, makeWrapper, nixosTests 2 + , nix-update-script 3 + , v2ray-geoip, v2ray-domain-list-community 4 + , assets ? [ v2ray-geoip v2ray-domain-list-community ] 3 5 }: 4 6 5 - let 6 - version = "4.45.0"; 7 + buildGoModule rec { 8 + pname = "v2ray-core"; 9 + version = "5.1.0"; 7 10 8 11 src = fetchFromGitHub { 9 12 owner = "v2fly"; 10 13 repo = "v2ray-core"; 11 14 rev = "v${version}"; 12 - sha256 = "sha256-vVCWCppGeAc7dwY0fX+G0CU3Vy6OBPpDBUOBK3ykg60="; 15 + hash = "sha256-87BtyaJN6qbinZQ+6MAwaK62YzbVnncj4qnEErG5tfA="; 13 16 }; 14 17 15 - vendorSha256 = "sha256-TbWMbIT578I8xbNsKgBeSP4MewuEKpfh62ZbJIeHgDs="; 18 + # `nix-update` doesn't support `vendorHash` yet. 19 + # https://github.com/Mic92/nix-update/pull/95 20 + vendorSha256 = "sha256-RuDCAgTzqwe5fUwa9ce2wRx4FPT8siRLbP7mU8/jg/Y="; 16 21 17 - assetsDrv = symlinkJoin { 18 - name = "v2ray-assets"; 19 - paths = assets; 20 - }; 22 + ldflags = [ "-s" "-w" "-buildid=" ]; 21 23 22 - core = buildGoModule rec { 23 - pname = "v2ray-core"; 24 - inherit version src; 24 + subPackages = [ "main" ]; 25 25 26 - inherit vendorSha256; 27 - 28 - doCheck = false; 29 - 30 - buildPhase = '' 31 - buildFlagsArray=(-v -p $NIX_BUILD_CORES -ldflags="-s -w") 32 - runHook preBuild 33 - go build "''${buildFlagsArray[@]}" -o v2ray ./main 34 - go build "''${buildFlagsArray[@]}" -o v2ctl -tags confonly ./infra/control/main 35 - runHook postBuild 36 - ''; 26 + nativeBuildInputs = [ makeWrapper ]; 37 27 38 - installPhase = '' 39 - install -Dm755 v2ray v2ctl -t $out/bin 40 - ''; 28 + installPhase = '' 29 + runHook preInstall 30 + install -Dm555 "$GOPATH"/bin/main $out/bin/v2ray 31 + install -Dm444 release/config/systemd/system/v2ray{,@}.service -t $out/lib/systemd/system 32 + install -Dm444 release/config/*.json -t $out/etc/v2ray 33 + runHook postInstall 34 + ''; 41 35 42 - meta = { 43 - homepage = "https://www.v2fly.org/en_US/"; 44 - description = "A platform for building proxies to bypass network restrictions"; 45 - license = with lib.licenses; [ mit ]; 46 - maintainers = with lib.maintainers; [ servalcatty ]; 47 - }; 36 + assetsDrv = symlinkJoin { 37 + name = "v2ray-assets"; 38 + paths = assets; 48 39 }; 49 40 50 - in runCommand "v2ray-${version}" { 51 - inherit src version; 52 - inherit (core) meta; 53 - 54 - nativeBuildInputs = [ makeWrapper ]; 41 + postFixup = '' 42 + wrapProgram $out/bin/v2ray \ 43 + --suffix XDG_DATA_DIRS : $assetsDrv/share 44 + substituteInPlace $out/lib/systemd/system/*.service \ 45 + --replace User=nobody DynamicUser=yes \ 46 + --replace /usr/local/bin/ $out/bin/ \ 47 + --replace /usr/local/etc/ /etc/ 48 + ''; 55 49 56 50 passthru = { 57 - inherit core; 58 - updateScript = ./update.sh; 59 - tests = { 60 - simple-vmess-proxy-test = nixosTests.v2ray; 51 + updateScript = nix-update-script { 52 + attrPath = "v2ray"; 61 53 }; 54 + tests.simple-vmess-proxy-test = nixosTests.v2ray; 62 55 }; 63 56 64 - } '' 65 - for file in ${core}/bin/*; do 66 - makeWrapper "$file" "$out/bin/$(basename "$file")" \ 67 - --set-default V2RAY_LOCATION_ASSET ${assetsDrv}/share/v2ray 68 - done 69 - '' 57 + meta = { 58 + homepage = "https://www.v2fly.org/en_US/"; 59 + description = "A platform for building proxies to bypass network restrictions"; 60 + license = with lib.licenses; [ mit ]; 61 + maintainers = with lib.maintainers; [ servalcatty ]; 62 + }; 63 + }
-49
pkgs/tools/networking/v2ray/update.sh
··· 1 - #!/usr/bin/env nix-shell 2 - #!nix-shell -i bash -p curl jq 3 - set -eo pipefail 4 - cd "$(dirname "${BASH_SOURCE[0]}")" 5 - 6 - version_nix=./default.nix 7 - deps_nix=./deps.nix 8 - nixpkgs=../../../.. 9 - 10 - old_core_rev=$(sed -En 's/.*\bversion = "(.*?)".*/\1/p' "$version_nix") 11 - echo "Current version:" >&2 12 - echo "core: $old_core_rev" >&2 13 - 14 - function fetch_latest_rev { 15 - curl "https://api.github.com/repos/v2fly/$1/releases" | 16 - jq '.[0].tag_name' --raw-output 17 - } 18 - 19 - core_rev=$(fetch_latest_rev 'v2ray-core') 20 - core_rev=${core_rev:1} 21 - echo "Latest version:" >&2 22 - echo "core: $core_rev" >&2 23 - 24 - if [[ $core_rev != $old_core_rev ]]; then 25 - echo "Prefetching core..." >&2 26 - { read hash; read store_path; } < <( 27 - nix-prefetch-url --unpack --print-path "https://github.com/v2fly/v2ray-core/archive/v$core_rev.zip" 28 - ) 29 - 30 - sed --in-place \ 31 - -e "s/\bversion = \".*\"/version = \"$core_rev\"/" \ 32 - -e "s/\bsha256 = \".*\"/sha256 = \"$hash\"/" \ 33 - -e "s/\bvendorSha256 = \".*\"/vendorSha256 = \"0000000000000000000000000000000000000000000000000000\"/" \ 34 - "$version_nix" 35 - fi 36 - 37 - echo "Prebuilding..." >&2 38 - set +o pipefail 39 - vendorSha256=$( 40 - nix-build "$nixpkgs" -A v2ray --no-out-link 2>&1 | 41 - tee /dev/stderr | 42 - sed -nE 's/.*got:\s*(sha256\S+)$/\1/p' 43 - ) 44 - [[ "$vendorSha256" ]] 45 - sed --in-place \ 46 - -e "s#vendorSha256 = \".*\"#vendorSha256 = \"$vendorSha256\"#" \ 47 - "$version_nix" 48 - 49 - echo "vendorSha256 updated" >&2