From 32940aeec4c1c25d63bc9c75c22ee92dd05283c4 Mon Sep 17 00:00:00 2001 From: Serval Date: Tue, 8 Sep 2020 03:23:12 +0800 Subject: [PATCH] v2ray: simplify nix --- pkgs/tools/networking/v2ray/default.nix | 59 +++++++++++++++++++++++-- pkgs/tools/networking/v2ray/generic.nix | 56 ----------------------- 2 files changed, 55 insertions(+), 60 deletions(-) delete mode 100644 pkgs/tools/networking/v2ray/generic.nix diff --git a/pkgs/tools/networking/v2ray/default.nix b/pkgs/tools/networking/v2ray/default.nix index d362810b56c8..183156036aa8 100644 --- a/pkgs/tools/networking/v2ray/default.nix +++ b/pkgs/tools/networking/v2ray/default.nix @@ -1,8 +1,8 @@ -{ callPackage, fetchFromGitHub, fetchurl +{ lib, fetchFromGitHub, fetchurl, linkFarm, buildGoModule, runCommand, makeWrapper, nixosTests , assetOverrides ? {} -, ... } @ args: +}: -callPackage ./generic.nix (rec { +let version = "4.27.5"; src = fetchFromGitHub { @@ -35,4 +35,55 @@ callPackage ./generic.nix (rec { } // assetOverrides; -} // args) + 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; + + 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 ]; + }; + + 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 +'' \ No newline at end of file diff --git a/pkgs/tools/networking/v2ray/generic.nix b/pkgs/tools/networking/v2ray/generic.nix deleted file mode 100644 index 04ac482e8985..000000000000 --- a/pkgs/tools/networking/v2ray/generic.nix +++ /dev/null @@ -1,56 +0,0 @@ -{ lib, linkFarm, buildGoModule, runCommand, makeWrapper, nixosTests - -# Version specific args -, version, src, assets, vendorSha256 -, ... }: - -let - 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; - - 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 ]; - }; - - passthru.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 -''