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