mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-08-25 17:55:21 +00:00
sing-box: support naive outbound
(cherry picked from commit e99be1b21f)
This commit is contained in:
committed by
github-actions[bot]
parent
3ec41a21fd
commit
a77e762efb
27
pkgs/by-name/si/sing-box/cronet-go.patch
Normal file
27
pkgs/by-name/si/sing-box/cronet-go.patch
Normal file
@@ -0,0 +1,27 @@
|
||||
--- a/internal/cronet/loader_unix.go
|
||||
+++ b/internal/cronet/loader_unix.go
|
||||
@@ -68,10 +68,11 @@
|
||||
}
|
||||
|
||||
var searchPaths []string
|
||||
- executablePath, err := os.Executable()
|
||||
- if err == nil {
|
||||
- searchPaths = append(searchPaths, filepath.Dir(executablePath))
|
||||
- }
|
||||
+ // executablePath, err := os.Executable()
|
||||
+ // if err == nil {
|
||||
+ // searchPaths = append(searchPaths, filepath.Dir(executablePath))
|
||||
+ // }
|
||||
+ searchPaths = append(searchPaths, "@out@/lib")
|
||||
|
||||
if ldPath := os.Getenv("LD_LIBRARY_PATH"); ldPath != "" {
|
||||
paths := filepath.SplitList(ldPath)
|
||||
@@ -85,7 +86,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
- searchPaths = append(searchPaths, "/usr/local/lib", "/usr/lib")
|
||||
+ // searchPaths = append(searchPaths, "/usr/local/lib", "/usr/lib")
|
||||
|
||||
for _, searchPath := range searchPaths {
|
||||
fullPath := filepath.Join(searchPath, libName)
|
||||
@@ -1,17 +1,28 @@
|
||||
{
|
||||
lib,
|
||||
buildGoModule,
|
||||
fetchFromGitHub,
|
||||
installShellFiles,
|
||||
buildPackages,
|
||||
coreutils,
|
||||
nix-update-script,
|
||||
cronet-go,
|
||||
fetchFromGitHub,
|
||||
go,
|
||||
installShellFiles,
|
||||
nixosTests,
|
||||
}:
|
||||
stdenvNoCC,
|
||||
|
||||
withStaticCronet ? true,
|
||||
withNaiveOutbound ? true,
|
||||
}:
|
||||
assert lib.assertMsg (
|
||||
withNaiveOutbound -> !withStaticCronet -> stdenvNoCC.hostPlatform.isLinux
|
||||
) "Dynamic linking to cronet-go is only available on Linux.";
|
||||
buildGoModule (finalAttrs: {
|
||||
pname = "sing-box";
|
||||
version = "1.13.15";
|
||||
|
||||
__structuredAttrs = true;
|
||||
|
||||
# nixpkgs-update: no auto update
|
||||
src = fetchFromGitHub {
|
||||
owner = "SagerNet";
|
||||
repo = "sing-box";
|
||||
@@ -34,15 +45,28 @@ buildGoModule (finalAttrs: {
|
||||
"with_ocm"
|
||||
"badlinkname"
|
||||
"tfogo_checklinkname0"
|
||||
];
|
||||
]
|
||||
++ lib.optional withNaiveOutbound "with_naive_outbound"
|
||||
++ lib.optional (withNaiveOutbound && !withStaticCronet) "with_purego";
|
||||
|
||||
subPackages = [
|
||||
"cmd/sing-box"
|
||||
];
|
||||
|
||||
env.CGO_ENABLED = 0;
|
||||
env = {
|
||||
CGO_ENABLED = 0;
|
||||
}
|
||||
// lib.optionalAttrs (withNaiveOutbound && withStaticCronet) {
|
||||
CGO_ENABLED = 1;
|
||||
CGO_LDFLAGS = "-fuse-ld=lld";
|
||||
};
|
||||
|
||||
nativeBuildInputs = [ installShellFiles ];
|
||||
nativeBuildInputs = [
|
||||
installShellFiles
|
||||
]
|
||||
++ lib.optional (withNaiveOutbound && withStaticCronet) buildPackages.rustc.llvmPackages.bintools;
|
||||
|
||||
buildInputs = lib.optional (withNaiveOutbound && withStaticCronet) cronet-go;
|
||||
|
||||
ldflags = [
|
||||
"-X=github.com/sagernet/sing-box/constant.Version=${finalAttrs.version}"
|
||||
@@ -50,6 +74,17 @@ buildGoModule (finalAttrs: {
|
||||
"-checklinkname=0"
|
||||
];
|
||||
|
||||
postConfigure = lib.optionalString withNaiveOutbound ''
|
||||
pushd vendor/github.com/sagernet/cronet-go
|
||||
chmod -R u+w .
|
||||
cp -r ${cronet-go}/ .
|
||||
# for !withStaticCronet
|
||||
patch -p1 < ${./cronet-go.patch}
|
||||
substituteInPlace internal/cronet/loader_unix.go \
|
||||
--subst-var out
|
||||
popd
|
||||
'';
|
||||
|
||||
postInstall = ''
|
||||
installShellCompletion release/completions/sing-box.{bash,fish,zsh}
|
||||
|
||||
@@ -60,10 +95,12 @@ buildGoModule (finalAttrs: {
|
||||
|
||||
install -Dm444 release/config/sing-box.rules $out/share/polkit-1/rules.d/sing-box.rules
|
||||
install -Dm444 release/config/sing-box-split-dns.xml $out/share/dbus-1/system.d/sing-box-split-dns.conf
|
||||
''
|
||||
+ lib.optionalString (withNaiveOutbound && !withStaticCronet) ''
|
||||
ln -s "${cronet-go}/lib/${go.GOOS}_${go.GOARCH}/libcronet.so" "$out/lib/"
|
||||
'';
|
||||
|
||||
passthru = {
|
||||
updateScript = nix-update-script { };
|
||||
tests = { inherit (nixosTests) sing-box; };
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user