{ lib, pkgs, ... }: let pythonPackages = pkgs.python3Packages; # Vosk is not present in the current nixpkgs revision, although it is one # of the backends shipped with Kdenlive. Package its upstream manylinux # wheel until it is available from nixpkgs. vosk = pythonPackages.buildPythonPackage rec { pname = "vosk"; version = "0.3.45"; format = "wheel"; src = pkgs.fetchPypi { inherit pname version format; python = "py3"; dist = "py3"; platform = "manylinux_2_12_x86_64.manylinux2010_x86_64"; hash = "sha256-JeAlCTxDmdcnj1Q1aO2MxUYKw6S/SMI2c6zh4l0mYZ8="; }; # The upstream wheel bundles libvosk.so without an RPATH. Patch it to # the Nix C++ runtime so importing vosk works outside a FHS environment. nativeBuildInputs = [ pkgs.autoPatchelfHook ]; buildInputs = [ pkgs.stdenv.cc.cc.lib ]; propagatedBuildInputs = with pythonPackages; [ cffi srt requests tqdm websockets ]; meta = with pkgs.lib; { description = "Offline open source speech recognition toolkit"; homepage = "https://alphacephei.com/vosk/"; license = licenses.asl20; }; }; # Kdenlive's speech-to-text scripts are launched through # /usr/bin/env python3. Keep this environment private to Kdenlive so the # other Python environments installed on the system remain independent. kdenlivePython = pkgs.python3.withPackages ( pythonPackages: with pythonPackages; [ pip numba openai-whisper srt torch vosk ] ); kdenlive = pkgs.kdePackages.kdenlive.overrideAttrs (old: { nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.makeWrapper ]; postFixup = (old.postFixup or "") + '' wrapProgram $out/bin/kdenlive \ --prefix PATH : ${kdenlivePython}/bin \ --set PYTHONNOUSERSITE 1 ''; }); in { home.packages = [ kdenlive ]; # Kdenlive otherwise prefers its mutable ~/.local/share/kdenlive/venv. # That venv was created by pip and its native Torch libraries do not have # the Nix runtime paths. Point Kdenlive at the immutable environment above. home.activation.kdenliveSpeechPython = lib.hm.dag.entryAfter [ "writeBoundary" ] '' run ${pkgs.kdePackages.kconfig}/bin/kwriteconfig6 \ --file "$HOME/.config/kdenliverc" \ --group speech \ --key speech_system_python true run ${pkgs.kdePackages.kconfig}/bin/kwriteconfig6 \ --file "$HOME/.config/kdenliverc" \ --group speech \ --key speech_system_python_path ${kdenlivePython}/bin/python3 ''; }