1{ lib 2, stdenv 3, blas 4, lapack 5, openfst 6, icu 7, pkg-config 8, fetchFromGitHub 9, python3 10, openblas 11, zlib 12, gfortran 13}: 14 15let 16 old-openfst = openfst.overrideAttrs (prev: { 17 version = "kag-unstable-2022-05-06"; 18 19 src = fetchFromGitHub { 20 owner = "kkm000"; 21 repo = "openfst"; 22 # required by https://github.com/daanzu/kaldi-fork-active-grammar/blob/e9c7d0ffca401cf312779d25f2c05a34b41ff696/cmake/third_party/openfst.cmake#L7 23 rev = "0bca6e76d24647427356dc242b0adbf3b5f1a8d9"; 24 sha256 = "1802rr14a03zl1wa5a0x1fa412kcvbgprgkadfj5s6s3agnn11rx"; 25 }; 26 buildInputs = [ zlib ]; 27 }); 28in 29 30assert blas.implementation == "openblas" && lapack.implementation == "openblas"; 31 32stdenv.mkDerivation rec { 33 pname = "kaldi"; 34 version = "kag-v2.1.0"; 35 36 src = fetchFromGitHub { 37 owner = "daanzu"; 38 repo = "kaldi-fork-active-grammar"; 39 rev = version; 40 sha256 = "+kT2xJRwDj/ECv/v/J1FpsINWOK8XkP9ZvZ9moFRl70="; 41 }; 42 43 patches = [ 44 ./0004-fork-cmake.patch 45 ./0006-fork-configure.patch 46 ]; 47 48 enableParallelBuilding = true; 49 50 buildInputs = [ 51 openblas 52 old-openfst 53 icu 54 ]; 55 56 nativeBuildInputs = [ 57 pkg-config 58 python3 59 gfortran 60 ]; 61 62 buildFlags = [ 63 "dragonfly" 64 "dragonflybin" 65 "bin" 66 "fstbin" 67 "lmbin" 68 ]; 69 70 postPatch = '' 71 # Replace the shebangs for the various build scripts 72 patchShebangs src 73 # Compatability with OpenBLAS 0.3.21 74 substituteInPlace src/matrix/cblas-wrappers.h \ 75 --replace stptri_ LAPACK_stptri \ 76 --replace dtptri_ LAPACK_dtptri \ 77 --replace sgetrf_ LAPACK_sgetrf \ 78 --replace dgetrf_ LAPACK_dgetrf \ 79 --replace sgetri_ LAPACK_sgetri \ 80 --replace dgetri_ LAPACK_dgetri \ 81 --replace sgesvd_ LAPACK_sgesvd \ 82 --replace dgesvd_ LAPACK_dgesvd \ 83 --replace ssptri_ LAPACK_ssptri \ 84 --replace dsptri_ LAPACK_dsptri \ 85 --replace ssptrf_ LAPACK_ssptrf \ 86 --replace dsptrf_ LAPACK_dsptrf 87 ''; 88 89 configurePhase = '' 90 cd src 91 ./configure --shared --fst-root="${old-openfst}" --use-cuda=no --openblas-root="${openblas}" --mathlib=OPENBLAS 92 ''; 93 94 installPhase = '' 95 # Fixes "patchelf: wrong ELF type" 96 find . -type f -name "*.o" -print0 | xargs -0 rm -f 97 mkdir -p $out/{bin,lib} 98 cp lib/* $out/lib/ 99 patchelf \ 100 --set-rpath "${lib.makeLibraryPath buildInputs}:$out/lib" \ 101 $out/lib/* 102 ''; 103 104 meta = with lib; { 105 description = "Speech Recognition Toolkit"; 106 homepage = "https://kaldi-asr.org"; 107 license = licenses.mit; 108 maintainers = with maintainers; [ ckie ]; 109 platforms = platforms.linux; 110 }; 111}