2024-05-15 15:35:15 +00:00
|
|
|
{ stdenv, lib, fetchurl, fetchzip, autoreconfHook, writeScript, fetchpatch
|
|
|
|
, modelUrl ? "", modelHash ? "" # Allow overriding the model URL and hash
|
|
|
|
}:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
let
|
|
|
|
modelVersionJSON = lib.importJSON ./model-version.json;
|
|
|
|
|
|
|
|
# Copy from https://gitlab.xiph.org/xiph/rnnoise/-/raw/v${version}/model_version
|
|
|
|
default_model_version = modelVersionJSON.version;
|
|
|
|
|
|
|
|
# Either use the default model or the one provided by package override
|
|
|
|
model_url = if (modelUrl == "") then "https://media.xiph.org/rnnoise/models/rnnoise_data-${default_model_version}.tar.gz" else modelUrl;
|
|
|
|
model_hash = if (modelHash == "") then modelVersionJSON.hash else modelHash;
|
|
|
|
|
|
|
|
in stdenv.mkDerivation (finalAttrs: {
|
2020-04-24 23:36:52 +00:00
|
|
|
pname = "rnnoise";
|
2024-05-15 15:35:15 +00:00
|
|
|
version = "0.2";
|
|
|
|
|
|
|
|
src = fetchzip {
|
|
|
|
urls = [
|
|
|
|
"https://gitlab.xiph.org/xiph/rnnoise/-/archive/v${finalAttrs.version}/rnnoise-v${finalAttrs.version}.tar.gz"
|
|
|
|
"https://github.com/xiph/rnnoise/archive/v${finalAttrs.version}.tar.gz"
|
|
|
|
];
|
|
|
|
hash = "sha256-Qaf+0iOprq7ILRWNRkBjsniByctRa/lFVqiU5ZInF/Q=";
|
|
|
|
};
|
|
|
|
|
|
|
|
patches = [
|
|
|
|
# remove when updating
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://github.com/xiph/rnnoise/commit/372f7b4b76cde4ca1ec4605353dd17898a99de38.patch";
|
|
|
|
hash = "sha256-Dzikb59hjVxd1XIEj/Je4evxtGORkaNcqE+zxOJMSvs=";
|
|
|
|
})
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
model = fetchurl {
|
|
|
|
url = model_url;
|
|
|
|
hash = model_hash;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
postPatch = ''
|
|
|
|
tar xvomf ${finalAttrs.model}
|
|
|
|
'';
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
nativeBuildInputs = [ autoreconfHook ];
|
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
install -Dt $out/bin examples/.libs/rnnoise_demo
|
|
|
|
'';
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
passthru.updateScript = writeScript "update-rnnoise.sh" ''
|
|
|
|
#!/usr/bin/env nix-shell
|
|
|
|
#!nix-shell -i bash -p curl jq common-updater-scripts nix nix-prefetch findutils moreutils
|
|
|
|
|
|
|
|
prefetch-sri() {
|
|
|
|
nix-prefetch-url "$1" | xargs nix hash to-sri --type sha256
|
|
|
|
}
|
|
|
|
|
|
|
|
res="$(curl ''${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} \
|
|
|
|
-sL "https://api.github.com/repos/xiph/rnnoise/tags?per_page=1")"
|
|
|
|
|
|
|
|
version="$(echo $res | jq '.[0].name | split("v") | .[1]' --raw-output)"
|
|
|
|
update-source-version ${finalAttrs.pname} "$version" --ignore-same-hash
|
|
|
|
|
|
|
|
model_version=$(curl -sL "https://raw.githubusercontent.com/xiph/rnnoise/v$version/model_version")
|
|
|
|
model_url="https://media.xiph.org/rnnoise/models/rnnoise_data-$model_version.tar.gz"
|
|
|
|
model_hash="$(prefetch-sri $model_url)"
|
|
|
|
|
|
|
|
modelJson=pkgs/development/libraries/rnnoise/model-version.json
|
|
|
|
|
|
|
|
jq --arg version "$model_version" \
|
|
|
|
--arg hash "$model_hash" \
|
|
|
|
'.version = $version | .hash = $hash' \
|
|
|
|
"$modelJson" | sponge "$modelJson"
|
|
|
|
'';
|
|
|
|
|
|
|
|
meta = {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Recurrent neural network for audio noise reduction";
|
2022-05-18 14:49:53 +00:00
|
|
|
homepage = "https://people.xiph.org/~jm/demo/rnnoise/";
|
2024-05-15 15:35:15 +00:00
|
|
|
license = lib.licenses.bsd3;
|
|
|
|
maintainers = with lib.maintainers; [ nh2 ];
|
2022-05-18 14:49:53 +00:00
|
|
|
mainProgram = "rnnoise_demo";
|
2024-05-15 15:35:15 +00:00
|
|
|
platforms = lib.platforms.all;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
})
|