nixpkgs/pkgs/tools/networking/v2ray/default.nix

91 lines
2.2 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-12-07 16:05:33 +00:00
version = "4.33.0";
2019-10-02 20:05:07 +01:00
src = fetchFromGitHub {
2020-11-09 17:08:43 +00:00
owner = "v2fly";
2019-10-02 20:05:07 +01:00
repo = "v2ray-core";
rev = "v${version}";
2020-12-07 16:05:33 +00:00
sha256 = "05w714i56nipp7m985g6zqq6ljz0w5ihxrgs93j10llfdd089iig";
2019-10-02 20:05:07 +01:00
};
2020-12-07 16:05:33 +00:00
vendorSha256 = "0ix5kxldgbcb10jh0l64lrh8qzla4qvsxi6vanb73y7lbsix120w";
2019-10-02 20:05:07 +01:00
assets = {
# MIT licensed
"geoip.dat" = let
2020-12-07 16:05:33 +00:00
geoipRev = "202012030015";
geoipSha256 = "1qy9h0721y5kjcp0s859lhj253jfi3d3i658gpc4kmij2l5dxm5w";
2019-10-02 20:05:07 +01:00
in fetchurl {
2020-11-09 17:08:43 +00:00
url = "https://github.com/v2fly/geoip/releases/download/${geoipRev}/geoip.dat";
2019-10-02 20:05:07 +01:00
sha256 = geoipSha256;
};
# MIT licensed
"geosite.dat" = let
2020-12-07 16:05:33 +00:00
geositeRev = "20201207123222";
geositeSha256 = "03xckk39rrda42cam2awbsh0gib6rhmz28asc8vx29lsp9g2bj6n";
2019-10-02 20:05:07 +01:00
in fetchurl {
2020-11-09 17:08:43 +00:00
url = "https://github.com/v2fly/domain-list-community/releases/download/${geositeRev}/dlc.dat";
2019-10-02 20:05:07 +01:00
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
'';
2020-11-09 17:08:43 +00:00
meta = {
2020-12-07 16:05:33 +00:00
homepage = "https://www.v2fly.org/en_US/";
2020-11-09 17:08:43 +00:00
description = "A platform for building proxies to bypass network restrictions";
2020-12-07 16:05:33 +00:00
license = with lib.licenses; [ mit ];
2020-11-09 17:08:43 +00:00
maintainers = with lib.maintainers; [ servalcatty ];
};
2020-09-07 20:23:12 +01:00
};
in runCommand "v2ray-${version}" {
inherit version;
2020-11-09 17:08:43 +00:00
inherit (core) meta;
2020-09-07 20:23:12 +01:00
nativeBuildInputs = [ makeWrapper ];
passthru = {
2020-12-07 16:05:33 +00:00
inherit core;
2020-09-07 20:23:12 +01: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 20:35:26 +01:00
''