Merge pull request #192196 from oxalica/pkg/v2ray
v2ray: 4.45.0 -> 5.1.0 and refactor
This commit is contained in:
commit
0ea721a941
|
@ -34,7 +34,7 @@ with lib;
|
||||||
|
|
||||||
Either `configFile` or `config` must be specified.
|
Either `configFile` or `config` must be specified.
|
||||||
|
|
||||||
See <https://www.v2fly.org/en_US/config/overview.html>.
|
See <https://www.v2fly.org/en_US/v5/config/overview.html>.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ with lib;
|
||||||
|
|
||||||
Either `configFile` or `config` must be specified.
|
Either `configFile` or `config` must be specified.
|
||||||
|
|
||||||
See <https://www.v2fly.org/en_US/config/overview.html>.
|
See <https://www.v2fly.org/en_US/v5/config/overview.html>.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -71,7 +71,7 @@ with lib;
|
||||||
name = "v2ray.json";
|
name = "v2ray.json";
|
||||||
text = builtins.toJSON cfg.config;
|
text = builtins.toJSON cfg.config;
|
||||||
checkPhase = ''
|
checkPhase = ''
|
||||||
${cfg.package}/bin/v2ray -test -config $out
|
${cfg.package}/bin/v2ray test -c $out
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -83,13 +83,15 @@ with lib;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
environment.etc."v2ray/config.json".source = configFile;
|
||||||
|
|
||||||
|
systemd.packages = [ cfg.package ];
|
||||||
|
|
||||||
systemd.services.v2ray = {
|
systemd.services.v2ray = {
|
||||||
description = "v2ray Daemon";
|
restartTriggers = [ config.environment.etc."v2ray/config.json".source ];
|
||||||
after = [ "network.target" ];
|
|
||||||
|
# Workaround: https://github.com/NixOS/nixpkgs/issues/81138
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
serviceConfig = {
|
|
||||||
ExecStart = "${cfg.package}/bin/v2ray -config ${configFile}";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import ./make-test-python.nix ({ lib, pkgs, ... }: let
|
||||||
port = 1081;
|
port = 1081;
|
||||||
listen = "127.0.0.1";
|
listen = "127.0.0.1";
|
||||||
protocol = "vmess";
|
protocol = "vmess";
|
||||||
settings.clients = [v2rayUser];
|
settings.clients = [ v2rayUser ];
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
outbounds = [
|
outbounds = [
|
||||||
|
@ -30,7 +30,7 @@ import ./make-test-python.nix ({ lib, pkgs, ... }: let
|
||||||
settings.vnext = [{
|
settings.vnext = [{
|
||||||
address = "127.0.0.1";
|
address = "127.0.0.1";
|
||||||
port = 1081;
|
port = 1081;
|
||||||
users = [v2rayUser];
|
users = [ v2rayUser ];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -49,6 +49,14 @@ import ./make-test-python.nix ({ lib, pkgs, ... }: let
|
||||||
inboundTag = "vmess_in";
|
inboundTag = "vmess_in";
|
||||||
outboundTag = "direct";
|
outboundTag = "direct";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Assert assets "geoip" and "geosite" are accessible.
|
||||||
|
{
|
||||||
|
type = "field";
|
||||||
|
ip = [ "geoip:private" ];
|
||||||
|
domain = [ "geosite:category-ads" ];
|
||||||
|
outboundTag = "direct";
|
||||||
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
let
|
let
|
||||||
generator = pkgsBuildBuild.buildGoModule rec {
|
generator = pkgsBuildBuild.buildGoModule rec {
|
||||||
pname = "v2ray-domain-list-community";
|
pname = "v2ray-domain-list-community";
|
||||||
version = "20220908131416";
|
version = "20220921050909";
|
||||||
src = fetchFromGitHub {
|
src = fetchFromGitHub {
|
||||||
owner = "v2fly";
|
owner = "v2fly";
|
||||||
repo = "domain-list-community";
|
repo = "domain-list-community";
|
||||||
rev = version;
|
rev = version;
|
||||||
sha256 = "sha256-LXtdyLINmUcyT2x9w7KCoLLifcYrSq6JN+2J9wbKjCI=";
|
sha256 = "sha256-ujslsVqUQ16LFdCwwKmY2SnoqNTRenI5cEreupt/6c4=";
|
||||||
};
|
};
|
||||||
vendorSha256 = "sha256-CCY3CgjA1w4svzmkaI2Jt272Rrt5UOt5sbVDAWRRfzk=";
|
vendorSha256 = "sha256-CCY3CgjA1w4svzmkaI2Jt272Rrt5UOt5sbVDAWRRfzk=";
|
||||||
meta = with lib; {
|
meta = with lib; {
|
||||||
|
|
|
@ -1,69 +1,63 @@
|
||||||
{ lib, fetchFromGitHub, fetchurl, symlinkJoin, buildGoModule, runCommand, makeWrapper, nixosTests
|
{ lib, fetchFromGitHub, symlinkJoin, buildGoModule, makeWrapper, nixosTests
|
||||||
, v2ray-geoip, v2ray-domain-list-community, assets ? [ v2ray-geoip v2ray-domain-list-community ]
|
, nix-update-script
|
||||||
|
, v2ray-geoip, v2ray-domain-list-community
|
||||||
|
, assets ? [ v2ray-geoip v2ray-domain-list-community ]
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
buildGoModule rec {
|
||||||
version = "4.45.0";
|
pname = "v2ray-core";
|
||||||
|
version = "5.1.0";
|
||||||
|
|
||||||
src = fetchFromGitHub {
|
src = fetchFromGitHub {
|
||||||
owner = "v2fly";
|
owner = "v2fly";
|
||||||
repo = "v2ray-core";
|
repo = "v2ray-core";
|
||||||
rev = "v${version}";
|
rev = "v${version}";
|
||||||
sha256 = "sha256-vVCWCppGeAc7dwY0fX+G0CU3Vy6OBPpDBUOBK3ykg60=";
|
hash = "sha256-87BtyaJN6qbinZQ+6MAwaK62YzbVnncj4qnEErG5tfA=";
|
||||||
};
|
};
|
||||||
|
|
||||||
vendorSha256 = "sha256-TbWMbIT578I8xbNsKgBeSP4MewuEKpfh62ZbJIeHgDs=";
|
# `nix-update` doesn't support `vendorHash` yet.
|
||||||
|
# https://github.com/Mic92/nix-update/pull/95
|
||||||
|
vendorSha256 = "sha256-RuDCAgTzqwe5fUwa9ce2wRx4FPT8siRLbP7mU8/jg/Y=";
|
||||||
|
|
||||||
|
ldflags = [ "-s" "-w" "-buildid=" ];
|
||||||
|
|
||||||
|
subPackages = [ "main" ];
|
||||||
|
|
||||||
|
nativeBuildInputs = [ makeWrapper ];
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
runHook preInstall
|
||||||
|
install -Dm555 "$GOPATH"/bin/main $out/bin/v2ray
|
||||||
|
install -Dm444 release/config/systemd/system/v2ray{,@}.service -t $out/lib/systemd/system
|
||||||
|
install -Dm444 release/config/*.json -t $out/etc/v2ray
|
||||||
|
runHook postInstall
|
||||||
|
'';
|
||||||
|
|
||||||
assetsDrv = symlinkJoin {
|
assetsDrv = symlinkJoin {
|
||||||
name = "v2ray-assets";
|
name = "v2ray-assets";
|
||||||
paths = assets;
|
paths = assets;
|
||||||
};
|
};
|
||||||
|
|
||||||
core = buildGoModule rec {
|
postFixup = ''
|
||||||
pname = "v2ray-core";
|
wrapProgram $out/bin/v2ray \
|
||||||
inherit version src;
|
--suffix XDG_DATA_DIRS : $assetsDrv/share
|
||||||
|
substituteInPlace $out/lib/systemd/system/*.service \
|
||||||
inherit vendorSha256;
|
--replace User=nobody DynamicUser=yes \
|
||||||
|
--replace /usr/local/bin/ $out/bin/ \
|
||||||
doCheck = false;
|
--replace /usr/local/etc/ /etc/
|
||||||
|
'';
|
||||||
buildPhase = ''
|
|
||||||
buildFlagsArray=(-v -p $NIX_BUILD_CORES -ldflags="-s -w")
|
|
||||||
runHook preBuild
|
|
||||||
go build "''${buildFlagsArray[@]}" -o v2ray ./main
|
|
||||||
go build "''${buildFlagsArray[@]}" -o v2ctl -tags confonly ./infra/control/main
|
|
||||||
runHook postBuild
|
|
||||||
'';
|
|
||||||
|
|
||||||
installPhase = ''
|
|
||||||
install -Dm755 v2ray v2ctl -t $out/bin
|
|
||||||
'';
|
|
||||||
|
|
||||||
meta = {
|
|
||||||
homepage = "https://www.v2fly.org/en_US/";
|
|
||||||
description = "A platform for building proxies to bypass network restrictions";
|
|
||||||
license = with lib.licenses; [ mit ];
|
|
||||||
maintainers = with lib.maintainers; [ servalcatty ];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
in runCommand "v2ray-${version}" {
|
|
||||||
inherit src version;
|
|
||||||
inherit (core) meta;
|
|
||||||
|
|
||||||
nativeBuildInputs = [ makeWrapper ];
|
|
||||||
|
|
||||||
passthru = {
|
passthru = {
|
||||||
inherit core;
|
updateScript = nix-update-script {
|
||||||
updateScript = ./update.sh;
|
attrPath = "v2ray";
|
||||||
tests = {
|
|
||||||
simple-vmess-proxy-test = nixosTests.v2ray;
|
|
||||||
};
|
};
|
||||||
|
tests.simple-vmess-proxy-test = nixosTests.v2ray;
|
||||||
};
|
};
|
||||||
|
|
||||||
} ''
|
meta = {
|
||||||
for file in ${core}/bin/*; do
|
homepage = "https://www.v2fly.org/en_US/";
|
||||||
makeWrapper "$file" "$out/bin/$(basename "$file")" \
|
description = "A platform for building proxies to bypass network restrictions";
|
||||||
--set-default V2RAY_LOCATION_ASSET ${assetsDrv}/share/v2ray
|
license = with lib.licenses; [ mit ];
|
||||||
done
|
maintainers = with lib.maintainers; [ servalcatty ];
|
||||||
''
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
#!/usr/bin/env nix-shell
|
|
||||||
#!nix-shell -i bash -p curl jq
|
|
||||||
set -eo pipefail
|
|
||||||
cd "$(dirname "${BASH_SOURCE[0]}")"
|
|
||||||
|
|
||||||
version_nix=./default.nix
|
|
||||||
deps_nix=./deps.nix
|
|
||||||
nixpkgs=../../../..
|
|
||||||
|
|
||||||
old_core_rev=$(sed -En 's/.*\bversion = "(.*?)".*/\1/p' "$version_nix")
|
|
||||||
echo "Current version:" >&2
|
|
||||||
echo "core: $old_core_rev" >&2
|
|
||||||
|
|
||||||
function fetch_latest_rev {
|
|
||||||
curl "https://api.github.com/repos/v2fly/$1/releases" |
|
|
||||||
jq '.[0].tag_name' --raw-output
|
|
||||||
}
|
|
||||||
|
|
||||||
core_rev=$(fetch_latest_rev 'v2ray-core')
|
|
||||||
core_rev=${core_rev:1}
|
|
||||||
echo "Latest version:" >&2
|
|
||||||
echo "core: $core_rev" >&2
|
|
||||||
|
|
||||||
if [[ $core_rev != $old_core_rev ]]; then
|
|
||||||
echo "Prefetching core..." >&2
|
|
||||||
{ read hash; read store_path; } < <(
|
|
||||||
nix-prefetch-url --unpack --print-path "https://github.com/v2fly/v2ray-core/archive/v$core_rev.zip"
|
|
||||||
)
|
|
||||||
|
|
||||||
sed --in-place \
|
|
||||||
-e "s/\bversion = \".*\"/version = \"$core_rev\"/" \
|
|
||||||
-e "s/\bsha256 = \".*\"/sha256 = \"$hash\"/" \
|
|
||||||
-e "s/\bvendorSha256 = \".*\"/vendorSha256 = \"0000000000000000000000000000000000000000000000000000\"/" \
|
|
||||||
"$version_nix"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Prebuilding..." >&2
|
|
||||||
set +o pipefail
|
|
||||||
vendorSha256=$(
|
|
||||||
nix-build "$nixpkgs" -A v2ray --no-out-link 2>&1 |
|
|
||||||
tee /dev/stderr |
|
|
||||||
sed -nE 's/.*got:\s*(sha256\S+)$/\1/p'
|
|
||||||
)
|
|
||||||
[[ "$vendorSha256" ]]
|
|
||||||
sed --in-place \
|
|
||||||
-e "s#vendorSha256 = \".*\"#vendorSha256 = \"$vendorSha256\"#" \
|
|
||||||
"$version_nix"
|
|
||||||
|
|
||||||
echo "vendorSha256 updated" >&2
|
|
Loading…
Reference in a new issue