about summary refs log tree commit diff
path: root/nixpkgs/pkgs/tools/audio/kaldi/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/tools/audio/kaldi/default.nix')
-rw-r--r--nixpkgs/pkgs/tools/audio/kaldi/default.nix99
1 files changed, 99 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/tools/audio/kaldi/default.nix b/nixpkgs/pkgs/tools/audio/kaldi/default.nix
new file mode 100644
index 000000000000..c9dc204ad405
--- /dev/null
+++ b/nixpkgs/pkgs/tools/audio/kaldi/default.nix
@@ -0,0 +1,99 @@
+{ lib
+, stdenv
+, openblas
+, blas
+, lapack
+, icu
+, cmake
+, pkg-config
+, fetchFromGitHub
+, python3
+, Accelerate
+, _experimental-update-script-combinators
+, common-updater-scripts
+, ripgrep
+, unstableGitUpdater
+, writeShellScript
+}:
+
+assert blas.implementation == "openblas" && lapack.implementation == "openblas";
+stdenv.mkDerivation (finalAttrs: {
+  pname = "kaldi";
+  version = "unstable-2023-10-13";
+
+  src = fetchFromGitHub {
+    owner = "kaldi-asr";
+    repo = "kaldi";
+    rev = "1b07b595b0bfd261c87f4efecd022481ed4a196f";
+    sha256 = "sha256-S4UD/J28McnJjFu5FH3ElwzXapceUUezfBCgI91eIi0=";
+  };
+
+  cmakeFlags = [
+    "-DKALDI_BUILD_TEST=off"
+    "-DBUILD_SHARED_LIBS=on"
+    "-DBLAS_LIBRARIES=-lblas"
+    "-DLAPACK_LIBRARIES=-llapack"
+    "-DFETCHCONTENT_SOURCE_DIR_OPENFST:PATH=${finalAttrs.passthru.sources.openfst}"
+  ];
+
+  buildInputs = [
+    openblas
+    icu
+  ] ++ lib.optionals stdenv.isDarwin [
+    Accelerate
+  ];
+
+  nativeBuildInputs = [
+    cmake
+    pkg-config
+    python3
+  ];
+
+  preConfigure = ''
+    cmakeFlagsArray+=(
+      # Extract version without the need for git.
+      # https://github.com/kaldi-asr/kaldi/blob/71f38e62cad01c3078555bfe78d0f3a527422d75/cmake/VersionHelper.cmake
+      # Patch number is not actually used by default so we can just ignore it.
+      # https://github.com/kaldi-asr/kaldi/blob/71f38e62cad01c3078555bfe78d0f3a527422d75/CMakeLists.txt#L214
+      "-DKALDI_VERSION=$(cat src/.version)"
+    )
+  '';
+
+  postInstall = ''
+    mkdir -p $out/share/kaldi
+    cp -r ../egs $out/share/kaldi
+  '';
+
+  passthru = {
+    sources = {
+      # rev from https://github.com/kaldi-asr/kaldi/blob/master/cmake/third_party/openfst.cmake
+      openfst = fetchFromGitHub {
+        owner = "kkm000";
+        repo = "openfst";
+        rev = "338225416178ac36b8002d70387f5556e44c8d05";
+        hash = "sha256-MGEUuw7ex+WcujVdxpO2Bf5sB6Z0edcAeLGqW/Lo1Hs=";
+      };
+    };
+
+    updateScript =
+      let
+        updateSource = unstableGitUpdater {};
+        updateOpenfst = writeShellScript "update-openfst" ''
+          hash=$(${ripgrep}/bin/rg --multiline --pcre2 --only-matching 'FetchContent_Declare\(\s*openfst[^)]*GIT_TAG\s*([0-9a-f]{40})' --replace '$1' "${finalAttrs.src}/cmake/third_party/openfst.cmake")
+          ${common-updater-scripts}/bin/update-source-version kaldi.sources.openfst "$hash" --source-key=out "--version-key=rev"
+        '';
+      in
+      _experimental-update-script-combinators.sequence [
+        updateSource
+        updateOpenfst
+      ];
+  };
+
+  meta = with lib; {
+    description = "Speech Recognition Toolkit";
+    homepage = "https://kaldi-asr.org";
+    license = licenses.mit;
+    maintainers = with maintainers; [ mic92 ];
+    platforms = platforms.unix;
+  };
+})