3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/pkgs/tools/networking/v2ray/default.nix

89 lines
2.1 KiB
Nix
Raw Normal View History

2020-09-07 20:23:12 +01:00
{ lib, fetchFromGitHub, fetchurl, linkFarm, buildGoModule, runCommand, makeWrapper, nixosTests
2019-10-02 20:05:07 +01:00
, assetOverrides ? {}
2020-09-07 20:23:12 +01:00
}:
2019-10-02 20:05:07 +01:00
2020-09-07 20:23:12 +01:00
let
2020-10-11 17:39:24 +01:00
version = "4.31.0";
2019-10-02 20:05:07 +01:00
src = fetchFromGitHub {
owner = "v2ray";
repo = "v2ray-core";
rev = "v${version}";
2020-10-11 17:39:24 +01:00
sha256 = "0s0blc05nrqm78qslv5xb42pjlx5v8qqwg0pwbzhxn9s71x2669m";
2019-10-02 20:05:07 +01:00
};
2020-10-11 17:39:24 +01:00
vendorSha256 = "0n2mf19fvgk5x0j2wwm4zk9xikzvl6cdvw26qar91wzcsraf5z2d";
2019-10-02 20:05:07 +01:00
assets = {
# MIT licensed
"geoip.dat" = let
2020-10-11 17:39:24 +01:00
geoipRev = "202009300006";
geoipSha256 = "1ss2izqlmrp5b5kpw804jk6c1nyimwlccbkikix3bwfaz4vlv1nc";
2019-10-02 20:05:07 +01:00
in fetchurl {
url = "https://github.com/v2ray/geoip/releases/download/${geoipRev}/geoip.dat";
sha256 = geoipSha256;
};
# MIT licensed
"geosite.dat" = let
2020-10-11 17:39:24 +01:00
geositeRev = "20201010021828";
geositeSha256 = "0gpfhcf4iyx7ip7rlkb0l1q64w84zvmcah52qyjwljs6l4p3hrj9";
2019-10-02 20:05:07 +01:00
in fetchurl {
url = "https://github.com/v2ray/domain-list-community/releases/download/${geositeRev}/dlc.dat";
sha256 = geositeSha256;
};
} // assetOverrides;
2020-09-07 20:23:12 +01: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 = ''
runHook preBuild
go build -o v2ray v2ray.com/core/main
go build -o v2ctl v2ray.com/core/infra/control/main
runHook postBuild
'';
installPhase = ''
install -Dm755 v2ray v2ctl -t $out/bin
'';
};
in runCommand "v2ray-${version}" {
inherit version;
nativeBuildInputs = [ makeWrapper ];
meta = {
homepage = "https://www.v2ray.com/en/index.html";
description = "A platform for building proxies to bypass network restrictions";
license = with lib.licenses; [ mit ];
maintainers = with lib.maintainers; [ servalcatty ];
};
passthru = {
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 20:35:26 +01:00
''