@@ -0,0 +1,88 @@
1+{ stdenv
2+, openblas
3+, blas
4+, lapack
5+, openfst
6+, icu
7+, cmake
8+, pkg-config
9+, fetchFromGitHub
10+, git
11+, python3
12+}:
13+
14+assert blas.implementation == "openblas" && lapack.implementation == "openblas";
15+let
16+ # rev from https://github.com/kaldi-asr/kaldi/blob/master/cmake/third_party/openfst.cmake
17+ openfst = fetchFromGitHub {
18+ owner = "kkm000";
19+ repo = "openfst";
20+ rev = "0bca6e76d24647427356dc242b0adbf3b5f1a8d9";
21+ sha256 = "1802rr14a03zl1wa5a0x1fa412kcvbgprgkadfj5s6s3agnn11rx";
22+ };
23+in
24+stdenv.mkDerivation {
25+ pname = "kaldi";
26+ version = "2020-12-26";
27+
28+ src = fetchFromGitHub {
29+ owner = "kaldi-asr";
30+ repo = "kaldi";
31+ rev = "813b73185a18725e4f6021981d17221d6ee23a19";
32+ sha256 = "sha256-lTqXTG5ZTPmhCgt+BVzOwjKEIj+bLGUa+IxJq+XtHUg=";
33+ };
34+
35+ cmakeFlags = [
36+ "-DKALDI_BUILD_TEST=off"
37+ "-DBUILD_SHARED_LIBS=on"
38+ ];
39+
40+ preConfigure = ''
41+ mkdir bin
42+ cat > bin/git <<'EOF'
43+ #!${stdenv.shell}
44+ if [[ "$1" == "--version" ]]; then
45+ # cmake checks this
46+ ${git}/bin/git --version
47+ elif [[ "$1" == "clone" ]]; then
48+ # mock this call:
49+
50+ # https://github.com/kaldi-asr/kaldi/blob/c9d8b9ad3fef89237ba5517617d977b7d70a7ed5/cmake/third_party/openfst.cmake#L5
51+ cp -r ${openfst} ''${@: -1}
52+ chmod -R +w ''${@: -1}
53+ elif [[ "$1" == "rev-list" ]]; then
54+ # fix up this call:
55+ # https://github.com/kaldi-asr/kaldi/blob/c9d8b9ad3fef89237ba5517617d977b7d70a7ed5/cmake/VersionHelper.cmake#L8
56+ echo 0
57+ fi
58+ true
59+ EOF
60+ chmod +x bin/git
61+ export PATH=$(pwd)/bin:$PATH
62+ '';
63+
64+ buildInputs = [
65+ openblas
66+ openfst
67+ icu
68+ ];
69+
70+ nativeBuildInputs = [
71+ cmake
72+ pkg-config
73+ python3
74+ ];
75+
76+ postInstall = ''
77+ mkdir -p $out/share/kaldi
78+ cp -r ../egs $out/share/kaldi
79+ '';
80+
81+ meta = with stdenv.lib; {
82+ description = "Speech Recognition Toolkit";
83+ homepage = "https://kaldi-asr.org";
84+ license = licenses.mit;
85+ maintainers = with maintainers; [ mic92 ];
86+ platforms = platforms.linux;
87+ };
88+}