Repository navigation
修复 NixOS TUN 包装核心,并支持 Linux 自动下载 sing-box - #32
Merged
Merged
Conversation
shebang / 非 ELF 核心改为 pkexec 启动并清掉错误的 bin 副本;Linux 安装官方动态包,缺少动态链接器时改用 musl 静态包。 Co-authored-by: Feri Muhammad <hdward-dev@users.noreply.github.com>
hdward-dev
marked this pull request as ready for review
October 31, 2026 05:10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
NixOS 上网络加速的 sing-box 放在应用数据目录
~/.local/share/AsterDock/AppData/network-accelerator/core/,不走系统 PATH。这份核心常常是几十到几百字节的#!/bin/sh包装:它用 nix store 里的ld-linux去执行旁边的sing-box.bin。TUN 授权把
getcap报出的cap_net_admin当成可用能力,于是把脚本复制到bin/sing-box并setcap。内核不会把文件能力套到 shebang 脚本上,复制时又丢掉旁边的sing-box.bin,启动以 127 退出,界面显示「加速核心已退出」。/dev/net/tun和 setuidpkexec本身是好的。另外
SingBoxInstallerService只接受 Windows / macOS,Linux 无法在应用内下载官方核心。改动
UseCapableCopy/CopyAndSetcap。有 pkexec 时直接对原始脚本LaunchWithPkexec,这样$DIR/sing-box.bin还在。已有的bin/sing-box和.sha256会被删掉,避免下次启动继续用坏副本。缺少 pkexec、用户取消、以及 NixOS 未启用security.polkit.enablePkexecWrapper的提示保持原样。/proc/pid/comm是sh或ld-linux,不是sing-box。只要进程已经不再是pkexec,就视为授权完成,避免一直等到「等待授权超时」。version能跑起来的副本继续免密复用。副本version失败时改走 pkexec,并清掉这份副本。sing-box-{version}-linux-{arch}.tar.gz,校验 Release 的 SHA-256,解出sing-box和随包的libcronet.so,再跑version。Windows / macOS 的包名不变。/lib64/ld-linux-x86-64.so.2(纯 Go 构建,但仍动态链接 glibc)。链接器不存在,或version报缺少共享库时,改下同版本官方…-linux-{arch}-musl.tar.gz。该包是静态 ELF,不依赖系统 sing-box,也不依赖 nix-ld。两边都起不来时,提示设置programs.nix-ld.enable = true;,或把已经能运行的核心放进应用数据目录的core文件夹。验证
dotnet run --project tests/NetworkAccelerator.Checks --configuration Release(431 项通过)。另外用官方 1.13.12 的 linux-amd64 与 musl 包做了解包:动态包读出的解释器是/lib64/ld-linux-x86-64.so.2,两个包的sing-box version都是 1.13.12。在 NixOS 上
rm -f ~/.local/share/AsterDock/AppData/network-accelerator/bin/sing-box ~/.local/share/AsterDock/AppData/network-accelerator/bin/sing-box.sha256apphub-tun起来。不要再复制脚本去做 setcap。/lib64/ld-linux-x86-64.so.2时会自动改用官方 musl 静态包。第一次开 TUN 会为 setcap 再要一次 pkexec,之后复用带能力的副本,不再每次询问。启用了 nix-ld 时则安装官方动态包,行为与普通 Linux 相同。