tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
lol
0
fork
atom
overview
issues
pulls
pipelines
v2ray: 4.45.0 -> 5.1.0 and refactor
oxalica
3 years ago
4f962f65
6f363379
+42
-97
2 changed files
expand all
collapse all
unified
split
pkgs
tools
networking
v2ray
default.nix
update.sh
+42
-48
pkgs/tools/networking/v2ray/default.nix
···
1
-
{ lib, fetchFromGitHub, fetchurl, symlinkJoin, buildGoModule, runCommand, makeWrapper, nixosTests
2
-
, v2ray-geoip, v2ray-domain-list-community, assets ? [ v2ray-geoip v2ray-domain-list-community ]
0
0
3
}:
4
5
-
let
6
-
version = "4.45.0";
0
7
8
src = fetchFromGitHub {
9
owner = "v2fly";
10
repo = "v2ray-core";
11
rev = "v${version}";
12
-
sha256 = "sha256-vVCWCppGeAc7dwY0fX+G0CU3Vy6OBPpDBUOBK3ykg60=";
13
};
14
15
-
vendorSha256 = "sha256-TbWMbIT578I8xbNsKgBeSP4MewuEKpfh62ZbJIeHgDs=";
0
0
16
17
-
assetsDrv = symlinkJoin {
18
-
name = "v2ray-assets";
19
-
paths = assets;
20
-
};
21
22
-
core = buildGoModule rec {
23
-
pname = "v2ray-core";
24
-
inherit version src;
25
26
-
inherit vendorSha256;
27
-
28
-
doCheck = false;
29
-
30
-
buildPhase = ''
31
-
buildFlagsArray=(-v -p $NIX_BUILD_CORES -ldflags="-s -w")
32
-
runHook preBuild
33
-
go build "''${buildFlagsArray[@]}" -o v2ray ./main
34
-
go build "''${buildFlagsArray[@]}" -o v2ctl -tags confonly ./infra/control/main
35
-
runHook postBuild
36
-
'';
37
38
-
installPhase = ''
39
-
install -Dm755 v2ray v2ctl -t $out/bin
40
-
'';
0
0
0
0
41
42
-
meta = {
43
-
homepage = "https://www.v2fly.org/en_US/";
44
-
description = "A platform for building proxies to bypass network restrictions";
45
-
license = with lib.licenses; [ mit ];
46
-
maintainers = with lib.maintainers; [ servalcatty ];
47
-
};
48
};
49
50
-
in runCommand "v2ray-${version}" {
51
-
inherit src version;
52
-
inherit (core) meta;
53
-
54
-
nativeBuildInputs = [ makeWrapper ];
0
0
0
55
56
passthru = {
57
-
inherit core;
58
-
updateScript = ./update.sh;
59
-
tests = {
60
-
simple-vmess-proxy-test = nixosTests.v2ray;
61
};
0
62
};
63
64
-
} ''
65
-
for file in ${core}/bin/*; do
66
-
makeWrapper "$file" "$out/bin/$(basename "$file")" \
67
-
--set-default V2RAY_LOCATION_ASSET ${assetsDrv}/share/v2ray
68
-
done
69
-
''
0
···
1
+
{ lib, fetchFromGitHub, symlinkJoin, buildGoModule, makeWrapper, nixosTests
2
+
, nix-update-script
3
+
, v2ray-geoip, v2ray-domain-list-community
4
+
, assets ? [ v2ray-geoip v2ray-domain-list-community ]
5
}:
6
7
+
buildGoModule rec {
8
+
pname = "v2ray-core";
9
+
version = "5.1.0";
10
11
src = fetchFromGitHub {
12
owner = "v2fly";
13
repo = "v2ray-core";
14
rev = "v${version}";
15
+
hash = "sha256-87BtyaJN6qbinZQ+6MAwaK62YzbVnncj4qnEErG5tfA=";
16
};
17
18
+
# `nix-update` doesn't support `vendorHash` yet.
19
+
# https://github.com/Mic92/nix-update/pull/95
20
+
vendorSha256 = "sha256-RuDCAgTzqwe5fUwa9ce2wRx4FPT8siRLbP7mU8/jg/Y=";
21
22
+
ldflags = [ "-s" "-w" "-buildid=" ];
0
0
0
23
24
+
subPackages = [ "main" ];
0
0
25
26
+
nativeBuildInputs = [ makeWrapper ];
0
0
0
0
0
0
0
0
0
0
27
28
+
installPhase = ''
29
+
runHook preInstall
30
+
install -Dm555 "$GOPATH"/bin/main $out/bin/v2ray
31
+
install -Dm444 release/config/systemd/system/v2ray{,@}.service -t $out/lib/systemd/system
32
+
install -Dm444 release/config/*.json -t $out/etc/v2ray
33
+
runHook postInstall
34
+
'';
35
36
+
assetsDrv = symlinkJoin {
37
+
name = "v2ray-assets";
38
+
paths = assets;
0
0
0
39
};
40
41
+
postFixup = ''
42
+
wrapProgram $out/bin/v2ray \
43
+
--suffix XDG_DATA_DIRS : $assetsDrv/share
44
+
substituteInPlace $out/lib/systemd/system/*.service \
45
+
--replace User=nobody DynamicUser=yes \
46
+
--replace /usr/local/bin/ $out/bin/ \
47
+
--replace /usr/local/etc/ /etc/
48
+
'';
49
50
passthru = {
51
+
updateScript = nix-update-script {
52
+
attrPath = "v2ray";
0
0
53
};
54
+
tests.simple-vmess-proxy-test = nixosTests.v2ray;
55
};
56
57
+
meta = {
58
+
homepage = "https://www.v2fly.org/en_US/";
59
+
description = "A platform for building proxies to bypass network restrictions";
60
+
license = with lib.licenses; [ mit ];
61
+
maintainers = with lib.maintainers; [ servalcatty ];
62
+
};
63
+
}
-49
pkgs/tools/networking/v2ray/update.sh
···
1
-
#!/usr/bin/env nix-shell
2
-
#!nix-shell -i bash -p curl jq
3
-
set -eo pipefail
4
-
cd "$(dirname "${BASH_SOURCE[0]}")"
5
-
6
-
version_nix=./default.nix
7
-
deps_nix=./deps.nix
8
-
nixpkgs=../../../..
9
-
10
-
old_core_rev=$(sed -En 's/.*\bversion = "(.*?)".*/\1/p' "$version_nix")
11
-
echo "Current version:" >&2
12
-
echo "core: $old_core_rev" >&2
13
-
14
-
function fetch_latest_rev {
15
-
curl "https://api.github.com/repos/v2fly/$1/releases" |
16
-
jq '.[0].tag_name' --raw-output
17
-
}
18
-
19
-
core_rev=$(fetch_latest_rev 'v2ray-core')
20
-
core_rev=${core_rev:1}
21
-
echo "Latest version:" >&2
22
-
echo "core: $core_rev" >&2
23
-
24
-
if [[ $core_rev != $old_core_rev ]]; then
25
-
echo "Prefetching core..." >&2
26
-
{ read hash; read store_path; } < <(
27
-
nix-prefetch-url --unpack --print-path "https://github.com/v2fly/v2ray-core/archive/v$core_rev.zip"
28
-
)
29
-
30
-
sed --in-place \
31
-
-e "s/\bversion = \".*\"/version = \"$core_rev\"/" \
32
-
-e "s/\bsha256 = \".*\"/sha256 = \"$hash\"/" \
33
-
-e "s/\bvendorSha256 = \".*\"/vendorSha256 = \"0000000000000000000000000000000000000000000000000000\"/" \
34
-
"$version_nix"
35
-
fi
36
-
37
-
echo "Prebuilding..." >&2
38
-
set +o pipefail
39
-
vendorSha256=$(
40
-
nix-build "$nixpkgs" -A v2ray --no-out-link 2>&1 |
41
-
tee /dev/stderr |
42
-
sed -nE 's/.*got:\s*(sha256\S+)$/\1/p'
43
-
)
44
-
[[ "$vendorSha256" ]]
45
-
sed --in-place \
46
-
-e "s#vendorSha256 = \".*\"#vendorSha256 = \"$vendorSha256\"#" \
47
-
"$version_nix"
48
-
49
-
echo "vendorSha256 updated" >&2
···
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0