Skip to content

Commit

Permalink
kaldi: Add update script
Browse files Browse the repository at this point in the history
Also switch to finalAttrs so that the values can be easily overridden.
  • Loading branch information
jtojnar committed Jun 6, 2023
1 parent e858807 commit 5abf11a
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions pkgs/tools/audio/kaldi/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@
, git
, python3
, Accelerate
, _experimental-update-script-combinators
, common-updater-scripts
, ripgrep
, unstableGitUpdater
, writeShellScript
}:

assert blas.implementation == "openblas" && lapack.implementation == "openblas";
let
# rev from https://github.com/kaldi-asr/kaldi/blob/master/cmake/third_party/openfst.cmake
openfst = fetchFromGitHub {
owner = "kkm000";
repo = "openfst";
rev = "338225416178ac36b8002d70387f5556e44c8d05";
sha256 = "sha256-MGEUuw7ex+WcujVdxpO2Bf5sB6Z0edcAeLGqW/Lo1Hs=";
};
in
stdenv.mkDerivation {
stdenv.mkDerivation (finalAttrs: {
pname = "kaldi";
version = "unstable-2022-09-26";

Expand All @@ -38,7 +34,7 @@ stdenv.mkDerivation {
"-DBUILD_SHARED_LIBS=on"
"-DBLAS_LIBRARIES=-lblas"
"-DLAPACK_LIBRARIES=-llapack"
"-DFETCHCONTENT_SOURCE_DIR_OPENFST:PATH=${openfst}"
"-DFETCHCONTENT_SOURCE_DIR_OPENFST:PATH=${finalAttrs.passthru.sources.openfst}"
];

buildInputs = [
Expand Down Expand Up @@ -69,11 +65,36 @@ stdenv.mkDerivation {
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;
};
}
})

1 comment on commit 5abf11a

@nixos-discourse
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/override-derivation-with-overrideattrs-any-way-to-handle-let-in/47307/2

Please sign in to comment.