sing-box: install shell completions directly

This commit is contained in:
Sizhe Zhao 2025-05-22 12:53:05 +08:00
parent 828eac07e7
commit dedb89c43d
No known key found for this signature in database
GPG key ID: ED1807251A7DA08F

View file

@ -1,10 +1,8 @@
{ {
lib, lib,
stdenv,
buildGoModule, buildGoModule,
fetchFromGitHub, fetchFromGitHub,
installShellFiles, installShellFiles,
buildPackages,
coreutils, coreutils,
nix-update-script, nix-update-script,
nixosTests, nixosTests,
@ -45,21 +43,14 @@ buildGoModule (finalAttrs: {
"-X=github.com/sagernet/sing-box/constant.Version=${finalAttrs.version}" "-X=github.com/sagernet/sing-box/constant.Version=${finalAttrs.version}"
]; ];
postInstall = postInstall = ''
let installShellCompletion release/completions/sing-box.{bash,fish,zsh}
emulator = stdenv.hostPlatform.emulator buildPackages;
in
''
installShellCompletion --cmd sing-box \
--bash <(${emulator} $out/bin/sing-box completion bash) \
--fish <(${emulator} $out/bin/sing-box completion fish) \
--zsh <(${emulator} $out/bin/sing-box completion zsh )
substituteInPlace release/config/sing-box{,@}.service \ substituteInPlace release/config/sing-box{,@}.service \
--replace-fail "/usr/bin/sing-box" "$out/bin/sing-box" \ --replace-fail "/usr/bin/sing-box" "$out/bin/sing-box" \
--replace-fail "/bin/kill" "${coreutils}/bin/kill" --replace-fail "/bin/kill" "${coreutils}/bin/kill"
install -Dm444 -t "$out/lib/systemd/system/" release/config/sing-box{,@}.service install -Dm444 -t "$out/lib/systemd/system/" release/config/sing-box{,@}.service
''; '';
passthru = { passthru = {
updateScript = nix-update-script { }; updateScript = nix-update-script { };