v2ray: 4.45.0 -> 5.1.0 and refactor

oxalica 4f962f65 6f363379

+42 -97
+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