1{
2 lib,
3 stdenv,
4 openblas,
5 blas,
6 lapack,
7 icu,
8 cmake,
9 pkg-config,
10 fetchFromGitHub,
11 python3,
12 _experimental-update-script-combinators,
13 common-updater-scripts,
14 ripgrep,
15 unstableGitUpdater,
16 writeShellScript,
17}:
18
19assert blas.implementation == "openblas" && lapack.implementation == "openblas";
20stdenv.mkDerivation (finalAttrs: {
21 pname = "kaldi";
22 version = "0-unstable-2025-04-28";
23
24 src = fetchFromGitHub {
25 owner = "kaldi-asr";
26 repo = "kaldi";
27 rev = "4b2bce7ffbb5777c40056784f7b6296037cebf29";
28 sha256 = "sha256-51IY07zasifeCMpW5RZ5x97JComBEddILwGpz/osEDs=";
29 };
30
31 cmakeFlags = [
32 "-DKALDI_BUILD_TEST=off"
33 "-DBUILD_SHARED_LIBS=on"
34 "-DBLAS_LIBRARIES=-lblas"
35 "-DLAPACK_LIBRARIES=-llapack"
36 "-DFETCHCONTENT_SOURCE_DIR_OPENFST:PATH=${finalAttrs.passthru.sources.openfst}"
37 ];
38
39 buildInputs = [
40 openblas
41 icu
42 ];
43
44 nativeBuildInputs = [
45 cmake
46 pkg-config
47 python3
48 ];
49
50 preConfigure = ''
51 cmakeFlagsArray+=(
52 # Extract version without the need for git.
53 # https://github.com/kaldi-asr/kaldi/blob/71f38e62cad01c3078555bfe78d0f3a527422d75/cmake/VersionHelper.cmake
54 # Patch number is not actually used by default so we can just ignore it.
55 # https://github.com/kaldi-asr/kaldi/blob/71f38e62cad01c3078555bfe78d0f3a527422d75/CMakeLists.txt#L214
56 "-DKALDI_VERSION=$(cat src/.version)"
57 )
58 '';
59
60 postInstall = ''
61 mkdir -p $out/share/kaldi
62 cp -r ../egs $out/share/kaldi
63 '';
64
65 dontCheckForBrokenSymlinks = true; # TODO: investigate
66
67 passthru = {
68 sources = {
69 # rev from https://github.com/kaldi-asr/kaldi/blob/master/cmake/third_party/openfst.cmake
70 openfst = fetchFromGitHub {
71 owner = "kkm000";
72 repo = "openfst";
73 rev = "338225416178ac36b8002d70387f5556e44c8d05";
74 hash = "sha256-y1E6bQgBfYt1Co02UutOyEM2FnETuUl144tHwypiX+M=";
75 # https://github.com/kkm000/openfst/issues/59
76 postFetch = ''(cd "$out"; patch -p1 < '${./gcc14.patch}')'';
77 };
78 };
79
80 updateScript =
81 let
82 updateSource = unstableGitUpdater { };
83 updateOpenfst = writeShellScript "update-openfst" ''
84 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")
85 ${common-updater-scripts}/bin/update-source-version kaldi.sources.openfst "$hash" --source-key=out "--version-key=rev"
86 '';
87 in
88 _experimental-update-script-combinators.sequence [
89 updateSource
90 updateOpenfst
91 ];
92 };
93
94 meta = with lib; {
95 description = "Speech Recognition Toolkit";
96 homepage = "https://kaldi-asr.org";
97 license = licenses.mit;
98 maintainers = with maintainers; [ mic92 ];
99 platforms = platforms.unix;
100 };
101})