10 modelHash ? "", # Allow overriding the model URL and hash
14 modelVersionJSON = lib.importJSON ./model-version.json;
16 # Copy from https://gitlab.xiph.org/xiph/rnnoise/-/raw/v${version}/model_version
17 default_model_version = modelVersionJSON.version;
19 # Either use the default model or the one provided by package override
21 if (modelUrl == "") then
22 "https://media.xiph.org/rnnoise/models/rnnoise_data-${default_model_version}.tar.gz"
25 model_hash = if (modelHash == "") then modelVersionJSON.hash else modelHash;
28 stdenv.mkDerivation (finalAttrs: {
34 "https://gitlab.xiph.org/xiph/rnnoise/-/archive/v${finalAttrs.version}/rnnoise-v${finalAttrs.version}.tar.gz"
35 "https://github.com/xiph/rnnoise/archive/v${finalAttrs.version}.tar.gz"
37 hash = "sha256-Qaf+0iOprq7ILRWNRkBjsniByctRa/lFVqiU5ZInF/Q=";
41 # remove when updating
43 url = "https://github.com/xiph/rnnoise/commit/372f7b4b76cde4ca1ec4605353dd17898a99de38.patch";
44 hash = "sha256-Dzikb59hjVxd1XIEj/Je4evxtGORkaNcqE+zxOJMSvs=";
54 tar xvomf ${finalAttrs.model}
57 nativeBuildInputs = [ autoreconfHook ];
60 install -Dt $out/bin examples/.libs/rnnoise_demo
63 passthru.updateScript = writeScript "update-rnnoise.sh" ''
64 #!/usr/bin/env nix-shell
65 #!nix-shell -i bash -p curl jq common-updater-scripts nix nix-prefetch findutils moreutils
68 nix-prefetch-url "$1" | xargs nix hash to-sri --type sha256
71 res="$(curl ''${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} \
72 -sL "https://api.github.com/repos/xiph/rnnoise/tags?per_page=1")"
74 version="$(echo $res | jq '.[0].name | split("v") | .[1]' --raw-output)"
75 update-source-version ${finalAttrs.pname} "$version" --ignore-same-hash
77 model_version=$(curl -sL "https://raw.githubusercontent.com/xiph/rnnoise/v$version/model_version")
78 model_url="https://media.xiph.org/rnnoise/models/rnnoise_data-$model_version.tar.gz"
79 model_hash="$(prefetch-sri $model_url)"
81 modelJson=pkgs/development/libraries/rnnoise/model-version.json
83 jq --arg version "$model_version" \
84 --arg hash "$model_hash" \
85 '.version = $version | .hash = $hash' \
86 "$modelJson" | sponge "$modelJson"
90 description = "Recurrent neural network for audio noise reduction";
91 homepage = "https://people.xiph.org/~jm/demo/rnnoise/";
92 license = lib.licenses.bsd3;
93 maintainers = with lib.maintainers; [ nh2 ];
94 mainProgram = "rnnoise_demo";
95 platforms = lib.platforms.all;