2020-09-07 21:23:12 +02:00
|
|
|
{ lib, fetchFromGitHub, fetchurl, linkFarm, buildGoModule, runCommand, makeWrapper, nixosTests
|
2019-10-02 21:05:07 +02:00
|
|
|
, assetOverrides ? {}
|
2020-09-07 21:23:12 +02:00
|
|
|
}:
|
2019-10-02 21:05:07 +02:00
|
|
|
|
2020-09-07 21:23:12 +02:00
|
|
|
let
|
2021-04-15 21:20:06 +02:00
|
|
|
version = "4.37.3";
|
2019-10-02 21:05:07 +02:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
2020-11-09 18:08:43 +01:00
|
|
|
owner = "v2fly";
|
2019-10-02 21:05:07 +02:00
|
|
|
repo = "v2ray-core";
|
|
|
|
rev = "v${version}";
|
2021-04-15 21:20:06 +02:00
|
|
|
sha256 = "0gbkjlrx4ddaxb5f21m3sxbb55ilvm5kqlrys6ckrx0xyz9hj38y";
|
2019-10-02 21:05:07 +02:00
|
|
|
};
|
|
|
|
|
2021-04-15 21:20:06 +02:00
|
|
|
vendorSha256 = "sha256-hPzIAXImAEJux1VRqCgslgn8giTf9BgZBcEZyF4Ut9Y=";
|
2020-07-08 19:14:28 +02:00
|
|
|
|
2019-10-02 21:05:07 +02:00
|
|
|
assets = {
|
|
|
|
# MIT licensed
|
|
|
|
"geoip.dat" = let
|
2021-04-15 21:20:06 +02:00
|
|
|
geoipRev = "202104150006";
|
|
|
|
geoipSha256 = "0ppm5r4bycjm7q0vnxj62q8639kp06sfkkkrkk5gibyrwisr4vrp";
|
2019-10-02 21:05:07 +02:00
|
|
|
in fetchurl {
|
2020-11-09 18:08:43 +01:00
|
|
|
url = "https://github.com/v2fly/geoip/releases/download/${geoipRev}/geoip.dat";
|
2019-10-02 21:05:07 +02:00
|
|
|
sha256 = geoipSha256;
|
|
|
|
};
|
|
|
|
|
|
|
|
# MIT licensed
|
|
|
|
"geosite.dat" = let
|
2021-04-15 21:20:06 +02:00
|
|
|
geositeRev = "20210415054336";
|
|
|
|
geositeSha256 = "0vs9fjbw45ipi7minh0r8zgh3pbwxqlrhwahpwyc6s0hyxgdi40w";
|
2019-10-02 21:05:07 +02:00
|
|
|
in fetchurl {
|
2020-11-09 18:08:43 +01:00
|
|
|
url = "https://github.com/v2fly/domain-list-community/releases/download/${geositeRev}/dlc.dat";
|
2019-10-02 21:05:07 +02:00
|
|
|
sha256 = geositeSha256;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // assetOverrides;
|
|
|
|
|
2020-09-07 21:23:12 +02:00
|
|
|
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 = ''
|
2021-01-08 20:23:06 +01:00
|
|
|
buildFlagsArray=(-v -p $NIX_BUILD_CORES -ldflags="-s -w")
|
2020-09-07 21:23:12 +02:00
|
|
|
runHook preBuild
|
2021-01-08 20:23:06 +01:00
|
|
|
go build "''${buildFlagsArray[@]}" -o v2ray ./main
|
|
|
|
go build "''${buildFlagsArray[@]}" -o v2ctl -tags confonly ./infra/control/main
|
2020-09-07 21:23:12 +02:00
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
install -Dm755 v2ray v2ctl -t $out/bin
|
|
|
|
'';
|
2020-11-09 18:08:43 +01:00
|
|
|
|
|
|
|
meta = {
|
2020-12-07 17:05:33 +01:00
|
|
|
homepage = "https://www.v2fly.org/en_US/";
|
2020-11-09 18:08:43 +01:00
|
|
|
description = "A platform for building proxies to bypass network restrictions";
|
2020-12-07 17:05:33 +01:00
|
|
|
license = with lib.licenses; [ mit ];
|
2020-11-09 18:08:43 +01:00
|
|
|
maintainers = with lib.maintainers; [ servalcatty ];
|
|
|
|
};
|
2020-09-07 21:23:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
in runCommand "v2ray-${version}" {
|
2021-03-08 19:18:07 +01:00
|
|
|
inherit src version;
|
2020-11-09 18:08:43 +01:00
|
|
|
inherit (core) meta;
|
2020-09-07 21:23:12 +02:00
|
|
|
|
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
|
|
|
|
|
|
|
passthru = {
|
2020-12-07 17:05:33 +01:00
|
|
|
inherit core;
|
2020-09-07 21:23:12 +02:00
|
|
|
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
|
2020-09-07 21:35:26 +02:00
|
|
|
''
|