2020-09-25 04:45:31 +00:00
|
|
|
{ lib, fetchFromGitHub, fetchurl, linkFarm, buildGoModule, runCommand, makeWrapper, nixosTests
|
2020-04-24 23:36:52 +00:00
|
|
|
, assetOverrides ? {}
|
2020-09-25 04:45:31 +00:00
|
|
|
}:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
let
|
2021-06-28 23:13:55 +00:00
|
|
|
version = "4.41.0";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
2020-11-21 19:51:51 +00:00
|
|
|
owner = "v2fly";
|
2020-04-24 23:36:52 +00:00
|
|
|
repo = "v2ray-core";
|
|
|
|
rev = "v${version}";
|
2021-06-28 23:13:55 +00:00
|
|
|
sha256 = "1300gl6y94i1488ja6kic0m5fa2qxakbdc06qd0lgkg6inzbm6gz";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
vendorSha256 = "sha256-oHKXDzufvTzOzBqFjBzu3vCwTF/FJMomopY3cUktwiM=";
|
2020-07-18 16:06:22 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
assets = {
|
|
|
|
# MIT licensed
|
|
|
|
"geoip.dat" = let
|
2021-06-28 23:13:55 +00:00
|
|
|
geoipRev = "202106240309";
|
|
|
|
geoipSha256 = "0ypydpgvizf9pfdxna3f6fqn1svsrkac0p3j9s63y55gbqpglacq";
|
2020-04-24 23:36:52 +00:00
|
|
|
in fetchurl {
|
2020-11-21 19:51:51 +00:00
|
|
|
url = "https://github.com/v2fly/geoip/releases/download/${geoipRev}/geoip.dat";
|
2020-04-24 23:36:52 +00:00
|
|
|
sha256 = geoipSha256;
|
|
|
|
};
|
|
|
|
|
|
|
|
# MIT licensed
|
|
|
|
"geosite.dat" = let
|
2021-06-28 23:13:55 +00:00
|
|
|
geositeRev = "20210626145509";
|
|
|
|
geositeSha256 = "0skhwwlzlyh8rvzyblg1l2xw1bawqs12i6zw5sv3d55pnw7wmf2z";
|
2020-04-24 23:36:52 +00:00
|
|
|
in fetchurl {
|
2020-11-21 19:51:51 +00:00
|
|
|
url = "https://github.com/v2fly/domain-list-community/releases/download/${geositeRev}/dlc.dat";
|
2020-04-24 23:36:52 +00:00
|
|
|
sha256 = geositeSha256;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // assetOverrides;
|
|
|
|
|
2020-09-25 04:45:31 +00: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-15 22:18:51 +00:00
|
|
|
buildFlagsArray=(-v -p $NIX_BUILD_CORES -ldflags="-s -w")
|
2020-09-25 04:45:31 +00:00
|
|
|
runHook preBuild
|
2021-01-15 22:18:51 +00:00
|
|
|
go build "''${buildFlagsArray[@]}" -o v2ray ./main
|
|
|
|
go build "''${buildFlagsArray[@]}" -o v2ctl -tags confonly ./infra/control/main
|
2020-09-25 04:45:31 +00:00
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
install -Dm755 v2ray v2ctl -t $out/bin
|
|
|
|
'';
|
2020-11-21 19:51:51 +00:00
|
|
|
|
|
|
|
meta = {
|
2020-12-09 12:39:15 +00:00
|
|
|
homepage = "https://www.v2fly.org/en_US/";
|
2020-11-21 19:51:51 +00:00
|
|
|
description = "A platform for building proxies to bypass network restrictions";
|
2020-12-09 12:39:15 +00:00
|
|
|
license = with lib.licenses; [ mit ];
|
2020-11-21 19:51:51 +00:00
|
|
|
maintainers = with lib.maintainers; [ servalcatty ];
|
|
|
|
};
|
2020-09-25 04:45:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
in runCommand "v2ray-${version}" {
|
2021-03-09 03:18:52 +00:00
|
|
|
inherit src version;
|
2020-11-21 19:51:51 +00:00
|
|
|
inherit (core) meta;
|
2020-09-25 04:45:31 +00:00
|
|
|
|
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
|
|
|
|
|
|
|
passthru = {
|
2020-12-09 12:39:15 +00:00
|
|
|
inherit core;
|
2020-09-25 04:45:31 +00: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
|
|
|
|
''
|