summary refs log tree commit diff
path: root/pkgs/tools/networking/v2ray/generic.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/tools/networking/v2ray/generic.nix')
-rw-r--r--pkgs/tools/networking/v2ray/generic.nix50
1 files changed, 50 insertions, 0 deletions
diff --git a/pkgs/tools/networking/v2ray/generic.nix b/pkgs/tools/networking/v2ray/generic.nix
new file mode 100644
index 00000000000..bf6e6cd55ae
--- /dev/null
+++ b/pkgs/tools/networking/v2ray/generic.nix
@@ -0,0 +1,50 @@
+{ lib, linkFarm, buildGoModule, runCommand, makeWrapper
+
+# Version specific args
+, version, src, assets
+, ... }:
+
+let
+  assetsDrv = linkFarm "v2ray-assets" (lib.mapAttrsToList (name: path: {
+    inherit name path;
+  }) assets);
+
+  core = buildGoModule rec {
+    pname = "v2ray-core";
+    inherit version src;
+
+    modSha256 = "11gsncy3449a7y6w6pr7acqabyj2q2a1q52f8fcl5cdz1vjbmmxi";
+
+    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;
+
+  buildInputs = [ assetsDrv core ];
+  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 ];
+  };
+
+} ''
+  for file in ${core}/bin/*; do
+    makeWrapper "$file" "$out/bin/$(basename "$file")" \
+      --set-default V2RAY_LOCATION_ASSET ${assetsDrv}
+  done
+''