Skip to content

feat: add nix and nixos flake support#456

Closed
longregen wants to merge 8 commits intospeaches-ai:masterfrom
longregen:master
Closed

feat: add nix and nixos flake support#456
longregen wants to merge 8 commits intospeaches-ai:masterfrom
longregen:master

Conversation

@longregen
Copy link
Copy Markdown

Hello there!

I love this project! It was exactly what I was looking for!

I don't know what's the appetite for this, but maybe it's useful for someone else. It almost doesn't touch any code -- only two python files to allow offline usage, so I can test that this works really offline.

Please feel free to close this pull request if it's too off-topic! I saw a flakes.nix file and thought that maybe some other nixos users would find this interesting.

@fedirz
Copy link
Copy Markdown
Collaborator

fedirz commented Jul 6, 2025

I've tried to test the changes, but I ran into errors with dlinfo being broken and also ctranslate2 not building. Here's the output.

NOTE: I'm using aarch64-darwin

❯ nix develop .\#speaches-cpu
warning: Git tree '/Users/fedir/code/speaches' is dirty
error: builder for '/nix/store/sscvjwljv17nq5b5g90pdhm0i9n380zl-ctranslate2-4.6.0.drv' failed with exit code 2;
       last 25 log lines:
       >                  from /tmp/nix-build-ctranslate2-4.6.0.drv-0/source/src/cpu/backend.cc:1:
       > /tmp/nix-build-ctranslate2-4.6.0.drv-0/source/third_party/ruy/ruy/pack_arm.h:492:9: warning: multi-line comment []
       >   492 | #endif  // (RUY_PLATFORM_NEON_64 || RUY_PLATFORM_NEON_32) && \
       >       |         ^
       > /tmp/nix-build-ctranslate2-4.6.0.drv-0/source/src/cpu/primitives.cc:17:12: fatal error: Accelerate/Accelerate.h: No such file or directory
       >    17 | #  include <Accelerate/Accelerate.h>
       >       |            ^~~~~~~~~~~~~~~~~~~~~~~~~
       > compilation terminated.
       > make[2]: *** [CMakeFiles/ctranslate2.dir/build.make:205: CMakeFiles/ctranslate2.dir/src/cpu/primitives.cc.o] Error 1
       > make[2]: *** Waiting for unfinished jobs....
       > In file included from /tmp/nix-build-ctranslate2-4.6.0.drv-0/source/src/cpu/kernels.cc:19:
       > /tmp/nix-build-ctranslate2-4.6.0.drv-0/source/src/cpu/vec.h: In instantiation of 'static void ctranslate2::cpu::Vec<T, ISA>::convert_and_store(float, U*, ctranslate2::dim_t) [with U = unsigned char; T = float; ctranslate2::cpu::CpuIsa ISA = ctranslate2::cpu::CpuIsa::GENERIC; ctranslate2::dim_t = long long int]':
       > /tmp/nix-build-ctranslate2-4.6.0.drv-0/source/src/cpu/kernels.cc:598:37:   required from 'float ctranslate2::cpu::quantize_s8_row(const float*, int8_t*, ctranslate2::dim_t, bool, const RoundFunc&) [with RoundFunc = float(float); int8_t = signed char; ctranslate2::dim_t = long long int]'
       > /tmp/nix-build-ctranslate2-4.6.0.drv-0/source/src/cpu/kernels.cc:634:38:   required from 'void ctranslate2::cpu::quantize_s8_batch(const float*, int8_t*, float*, ctranslate2::dim_t, ctranslate2::dim_t, bool, const RoundFunc&) [with RoundFunc = float(float); int8_t = signed char; ctranslate2::dim_t = long long int]'
       > /tmp/nix-build-ctranslate2-4.6.0.drv-0/source/src/cpu/kernels.cc:648:26:   required from here
       > /tmp/nix-build-ctranslate2-4.6.0.drv-0/source/src/cpu/vec.h:148:65: warning: unused parameter 'count' []
       >   148 |       static inline void convert_and_store(float v, U* a, dim_t count) {
       >       |                                                           ~~~~~~^~~~~
       > /tmp/nix-build-ctranslate2-4.6.0.drv-0/source/src/cpu/vec.h: In instantiation of 'static void ctranslate2::cpu::Vec<T, ISA>::convert_and_store(float, U*, ctranslate2::dim_t) [with U = signed char; T = float; ctranslate2::cpu::CpuIsa ISA = ctranslate2::cpu::CpuIsa::GENERIC; ctranslate2::dim_t = long long int]':
       > /tmp/nix-build-ctranslate2-4.6.0.drv-0/source/src/cpu/kernels.cc:609:37:   required from 'float ctranslate2::cpu::quantize_s8_row(const float*, int8_t*, ctranslate2::dim_t, bool, const RoundFunc&) [with RoundFunc = float(float); int8_t = signed char; ctranslate2::dim_t = long long int]'
       > /tmp/nix-build-ctranslate2-4.6.0.drv-0/source/src/cpu/kernels.cc:634:38:   required from 'void ctranslate2::cpu::quantize_s8_batch(const float*, int8_t*, float*, ctranslate2::dim_t, ctranslate2::dim_t, bool, const RoundFunc&) [with RoundFunc = float(float); int8_t = signed char; ctranslate2::dim_t = long long int]'
       > /tmp/nix-build-ctranslate2-4.6.0.drv-0/source/src/cpu/kernels.cc:648:26:   required from here
       > /tmp/nix-build-ctranslate2-4.6.0.drv-0/source/src/cpu/vec.h:148:65: warning: unused parameter 'count' []
       > make[1]: *** [CMakeFiles/Makefile2:358: CMakeFiles/ctranslate2.dir/all] Error 2
       > make: *** [Makefile:136: all] Error 2
       For full logs, run:
         nix log /nix/store/sscvjwljv17nq5b5g90pdhm0i9n380zl-ctranslate2-4.6.0.drv
error: 1 dependencies of derivation '/nix/store/fbq0qriglqxw21zv3jbi4wxxcf0xma1y-speaches-0.1.0-env.drv' failed to build

Applying this diff does fix nix (run|shell|develop) .#speaches-cpu. Is there a better way to address this?

diff --git a/flake.nix b/flake.nix
index 10d4902..4ad8296 100644
--- a/flake.nix
+++ b/flake.nix
@@ -24,21 +24,21 @@
           pyPackages = prev."${pythonVersion}Packages";
         in {
           # Override ctranslate2 for CUDA support
-          ctranslate2 =
-            if cudaSupport && system == "x86_64-linux"
-            then
-              prev.ctranslate2.override {
-                stdenv = prev.gcc11Stdenv;
-                withCUDA = true;
-                withCuDNN = true;
-                cudaPackages = prev.cudaPackages_12;
-              }
-            else
-              prev.ctranslate2.override {
-                stdenv = prev.gcc11Stdenv;
-                withCUDA = false;
-                withCuDNN = false;
-              };
+          # ctranslate2 =
+          #   if cudaSupport && system == "x86_64-linux"
+          #   then
+          #     prev.ctranslate2.override {
+          #       stdenv = prev.gcc11Stdenv;
+          #       withCUDA = true;
+          #       withCuDNN = true;
+          #       cudaPackages = prev.cudaPackages_12;
+          #     }
+          #   else
+          #     prev.ctranslate2.override {
+          #       stdenv = prev.gcc11Stdenv;
+          #       withCUDA = false;
+          #       withCuDNN = false;
+          #     };
 
           "${pythonVersion}Packages" =
             pyPackages
@@ -127,6 +127,7 @@
           pkgs = import nixpkgs {
             inherit system;
             config.allowUnfree = true;
+            config.allowBroken = true;
             overlays = [overlay];
           };
 
diff --git a/nix/dependencies/phonemizer-fork.nix b/nix/dependencies/phonemizer-fork.nix
index 8ae1ba5..d5cd7a3 100644
--- a/nix/dependencies/phonemizer-fork.nix
+++ b/nix/dependencies/phonemizer-fork.nix
@@ -15,7 +15,7 @@ prev.buildPythonPackage rec {
     joblib
     segments
     attrs
-    dlinfo
+    (dlinfo.overridePythonAttrs (old: { doCheck = false; }))
   ];
   
   doCheck = false;

I love this project! It was exactly what I was looking for!

Hey, I'm happy you're finding this project useful

I saw a flakes.nix file and thought that maybe some other nixos users would find this interesting.

I'm finding this very interesting. I've always wanted to have speaches available as a NixOS service!

I would love to merge these changes in, but I'm concerned that I won't have either the time or the skill to maintain the Nix configuration as dependencies of the project evolve. Do you think you'll be able to help with the maintenance of the Nix files? Otherwise, I worry they might become stale and cause issues for users.


Side note: I really like what you've done with nix-hug. I've had a similar idea of declaratively managing HF cache for some time now. Pretty cool to see someone create a project for this.

@longregen
Copy link
Copy Markdown
Author

Hey there! I'm glad you found it useful. I could commit to maintain this; at least checking on it every month or so. Not sure if any other users would be interested though! I guess you won't like to have the PR hanging around, feel free to close it, I guess organically other nixos users might arrive at this thread.

I'll run the build on a mac build box I have somewhere and report back to you.

@longregen longregen force-pushed the master branch 4 times, most recently from ccf9c80 to 75c2cba Compare July 14, 2025 18:20
@longregen longregen force-pushed the master branch 3 times, most recently from ef9b32f to 2e1058b Compare October 17, 2025 12:58
@longregen longregen force-pushed the master branch 2 times, most recently from 3be6270 to 2934204 Compare December 30, 2025 16:33
@longregen longregen force-pushed the master branch 5 times, most recently from ecd3e51 to 9cb2089 Compare March 5, 2026 13:51
@longregen longregen force-pushed the master branch 8 times, most recently from 8e330a3 to 752fc98 Compare March 18, 2026 05:11
@longregen longregen force-pushed the master branch 18 times, most recently from d91d609 to b3eaf1a Compare March 27, 2026 03:37
@longregen longregen force-pushed the master branch 2 times, most recently from 951cba0 to 3634104 Compare March 27, 2026 14:24
longregen and others added 7 commits March 27, 2026 13:43
Rework the realtime WebSocket and WebRTC pipelines with improved TTS
bridging, input audio buffer handling, and text chunking. Add phrase-level
streaming, interrupt support, and conversation state management.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…artup summary

Introduce ExecutorRegistry for centralized model management, add Silero
VAD v6 executor, configurable GPU memory limits via ORT options, and a
startup summary log with loaded models, TTLs, and memory configuration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Wrap each OpenTelemetry instrumentor import in try/except so the service
starts even when individual instrumentation packages have version
mismatches (e.g. httpx vs util-http). Relax pyproject.toml otel pins
from ==0.50b0 to >=0.55b0 to allow compatible version resolution.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Wrap list_remote_models() in try/except for OSError/ValueError so
  HF_HUB_OFFLINE=1 environments don't crash when iterating executors
- Add offline-safe error handling to /v1/registry endpoint
- Lazy-import torch and pyannote in wespeaker and diarization modules
  so they can be imported without torch installed (CPU-only builds)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
New test suites:
- Realtime WebSocket e2e tests (14 scenarios)
- Conversation state, input audio buffer, interruption tests
- Phrase chunker, response handler, session config tests
- VAD v6, otel imports tests
- Performance and allocation benchmarks

Test infrastructure:
- Add requires_chat_backend and requires_gated_hf_model markers
- Require explicit CHAT_COMPLETION_MODEL for chat tests
- Skip tests gracefully when HF_TOKEN, torch, or HF_HUB_CACHE unavailable
- Update GPU memory limit assertion to match new 1GB default

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add running-tests guide, installation docs, and troubleshooting page.
Update usage docs for dynamic loading, model discovery, realtime API,
speech embedding, STT, TTS, VAD, and voice chat with improved examples.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Nix packaging:
- Add flake.nix with multi-Python (3.12-3.15) and CUDA/CPU variants
- Add nix/dependencies.nix with all custom Python packages
- Add nix/module.nix for NixOS service integration
- Add nix-hug model cache for offline HuggingFace model access
- Guard Piper TTS behind availability check for non-Linux systems
- Guard NixOS VM checks behind isLinux for macOS compatibility

E2e tests (64 assertions per variant):
- Health, diagnostics, model management endpoints
- TTS in WAV/MP3/FLAC/Opus with multiple voices and model aliases
- STT with whisper-base and whisper-tiny.en, all response formats
- Translation, VAD (silero v5+v6), model load/unload lifecycle
- TTS->STT round-trip pipeline with quality verification
- NixOS VM test with 35 assertions matching shell script coverage

Dev tooling:
- Add speaches-python wrapper with ffmpeg/espeak-ng on PATH
- Add test dependencies (srt, webvtt_py, pytest_antilru)
- Fix mkdocs-render-swagger-plugin build (pyproject=true)
- Update CI workflows for nix integration

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@longregen longregen closed this Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants