07d6a74cbb
GitOrigin-RevId: f5e8bdd07d1afaabf6b37afc5497b1e498b8046f
89 lines
2.3 KiB
Nix
89 lines
2.3 KiB
Nix
{ lib, fetchFromGitHub, fetchurl, linkFarm, buildGoModule, runCommand, makeWrapper, nixosTests
|
|
, assetOverrides ? {}
|
|
}:
|
|
|
|
let
|
|
version = "4.36.2";
|
|
|
|
src = fetchFromGitHub {
|
|
owner = "v2fly";
|
|
repo = "v2ray-core";
|
|
rev = "v${version}";
|
|
sha256 = "1gvzr4kq4klld8m0jv6mizgrx3xj6s2i69kl9vmh5n355bakb7kk";
|
|
};
|
|
|
|
vendorSha256 = "sha256-8O0xUNIdu3W//LtwiMZlSs1wkpa6Jt+vFkTavz6TBKU=";
|
|
|
|
assets = {
|
|
# MIT licensed
|
|
"geoip.dat" = let
|
|
geoipRev = "202103170314";
|
|
geoipSha256 = "147kajdhby92yxsvcpa6bpk11ilzvc4nj7rc0h84wp2f0y692kq2";
|
|
in fetchurl {
|
|
url = "https://github.com/v2fly/geoip/releases/download/${geoipRev}/geoip.dat";
|
|
sha256 = geoipSha256;
|
|
};
|
|
|
|
# MIT licensed
|
|
"geosite.dat" = let
|
|
geositeRev = "20210317031429";
|
|
geositeSha256 = "0nzd0ll0x7hv75cbh1i3kgmffasi002a8n3mjw22zywj71v2jwmz";
|
|
in fetchurl {
|
|
url = "https://github.com/v2fly/domain-list-community/releases/download/${geositeRev}/dlc.dat";
|
|
sha256 = geositeSha256;
|
|
};
|
|
|
|
} // assetOverrides;
|
|
|
|
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 = ''
|
|
buildFlagsArray=(-v -p $NIX_BUILD_CORES -ldflags="-s -w")
|
|
runHook preBuild
|
|
go build "''${buildFlagsArray[@]}" -o v2ray ./main
|
|
go build "''${buildFlagsArray[@]}" -o v2ctl -tags confonly ./infra/control/main
|
|
runHook postBuild
|
|
'';
|
|
|
|
installPhase = ''
|
|
install -Dm755 v2ray v2ctl -t $out/bin
|
|
'';
|
|
|
|
meta = {
|
|
homepage = "https://www.v2fly.org/en_US/";
|
|
description = "A platform for building proxies to bypass network restrictions";
|
|
license = with lib.licenses; [ mit ];
|
|
maintainers = with lib.maintainers; [ servalcatty ];
|
|
};
|
|
};
|
|
|
|
in runCommand "v2ray-${version}" {
|
|
inherit src version;
|
|
inherit (core) meta;
|
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
|
|
|
passthru = {
|
|
inherit core;
|
|
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
|
|
''
|