Skip to content

Commit d7dc990

Browse files
committed
fix: resolve protobuf ABI conflict in Nix build
Override sentencepiece to use system protobuf instead of embedded version, preventing segmentation fault when both sentencepiece and onnxruntime are linked with different protobuf versions. Also improves library path wrapping for runtime dependencies.
1 parent ae1f852 commit d7dc990

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

flake.nix

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@
101101

102102
packages = let
103103
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
104+
105+
# Override sentencepiece to use the same protobuf as onnxruntime
106+
# to avoid ABI conflicts
107+
sentencepieceFixed = pkgs.sentencepiece.overrideAttrs (old: {
108+
buildInputs = (old.buildInputs or []) ++ [ pkgs.protobuf ];
109+
cmakeFlags = (old.cmakeFlags or []) ++ [
110+
"-DSPM_USE_BUILTIN_PROTOBUF=OFF"
111+
];
112+
});
113+
104114
sonoriPkg = pkgs.rustPlatform.buildRustPackage rec {
105115
pname = "sonori";
106116
version = cargoToml.package.version;
@@ -123,6 +133,7 @@
123133
vulkan-headers
124134
shaderc
125135
git
136+
makeWrapper # For wrapping binary with library paths
126137
];
127138

128139
buildInputs = with pkgs; [
@@ -142,16 +153,16 @@
142153
fftw
143154
curl
144155
ctranslate2
145-
sentencepiece
146156
wtype
147157
vulkan-loader
148158
vulkan-headers
149159
openblas
150160
openblas.dev
151161
onnxruntime
152-
];
162+
protobuf # Ensure consistent protobuf version
163+
] ++ [ sentencepieceFixed ]; # Use our fixed sentencepiece
153164

154-
# Environment variable to point ort-sys to system ONNX Runtime
165+
# Use system ONNX Runtime for Silero VAD
155166
ORT_STRATEGY = "system";
156167

157168
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
@@ -162,6 +173,22 @@
162173
doCheck = false;
163174

164175
postInstall = ''
176+
# Wrap binary with required library paths
177+
wrapProgram $out/bin/sonori \
178+
--prefix LD_LIBRARY_PATH : ${pkgs.lib.makeLibraryPath [
179+
pkgs.libxkbcommon
180+
pkgs.wayland
181+
pkgs.xorg.libX11
182+
pkgs.xorg.libXcursor
183+
pkgs.xorg.libXi
184+
pkgs.xorg.libXrandr
185+
pkgs.vulkan-loader
186+
pkgs.openblas
187+
pkgs.onnxruntime
188+
pkgs.alsa-lib
189+
pkgs.portaudio
190+
]}
191+
165192
# Install desktop file
166193
mkdir -p $out/share/applications
167194
install -m 644 ${./desktop/sonori.desktop} $out/share/applications/

0 commit comments

Comments
 (0)