@@ -1,8 +1,8 @@
1−{ callPackage, fetchFromGitHub, fetchurl
1+{ lib, fetchFromGitHub, fetchurl, linkFarm, buildGoModule, runCommand, makeWrapper, nixosTests
22, assetOverrides ? {}
3−, ... } @ args:
3+}:
44
5−callPackage ./generic.nix (rec {
5+let
66 version = "4.27.5";
77
88 src = fetchFromGitHub {
@@ -35,4 +35,55 @@ callPackage ./generic.nix (rec {
3535
3636 } // assetOverrides;
3737
38−} // args)
38+ assetsDrv = linkFarm "v2ray-assets" (lib.mapAttrsToList (name: path: {
39+ inherit name path;
40+ }) assets);
41+
42+ core = buildGoModule rec {
43+ pname = "v2ray-core";
44+ inherit version src;
45+
46+ inherit vendorSha256;
47+
48+ doCheck = false;
49+
50+ buildPhase = ''
51+ runHook preBuild
52+
53+ go build -o v2ray v2ray.com/core/main
54+ go build -o v2ctl v2ray.com/core/infra/control/main
55+
56+ runHook postBuild
57+ '';
58+
59+ installPhase = ''
60+ install -Dm755 v2ray v2ctl -t $out/bin
61+ '';
62+ };
63+
64+in runCommand "v2ray-${version}" {
65+ inherit version;
66+
67+ buildInputs = [ assetsDrv core ];
68+ nativeBuildInputs = [ makeWrapper ];
69+
70+ meta = {
71+ homepage = "https://www.v2ray.com/en/index.html";
72+ description = "A platform for building proxies to bypass network restrictions";
73+ license = with lib.licenses; [ mit ];
74+ maintainers = with lib.maintainers; [ servalcatty ];
75+ };
76+
77+ passthru = {
78+ updateScript = ./update.sh;
79+ tests = {
80+ simple-vmess-proxy-test = nixosTests.v2ray;
81+ };
82+ };
83+
84+} ''
85+ for file in ${core}/bin/*; do
86+ makeWrapper "$file" "$out/bin/$(basename "$file")" \
87+ --set-default V2RAY_LOCATION_ASSET ${assetsDrv}
88+ done
89+''