Skip to content

Commit

Permalink
Merge pull request NixOS#305348 from JohnRTitor/rnnoise
Browse files Browse the repository at this point in the history
rnnoise: 2021-01-22 -> 0.2
  • Loading branch information
Artturin authored Apr 30, 2024
2 parents 0e68477 + 614eb0b commit fcd0c62
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 12 deletions.
80 changes: 68 additions & 12 deletions pkgs/development/libraries/rnnoise/default.nix
Original file line number Diff line number Diff line change
@@ -1,28 +1,84 @@
{ stdenv, lib, fetchFromGitHub, autoreconfHook }:
{ stdenv, lib, fetchurl, fetchzip, autoreconfHook, writeScript, fetchpatch
, modelUrl ? "", modelHash ? "" # Allow overriding the model URL and hash
}:

stdenv.mkDerivation (rec {
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: {
pname = "rnnoise";
version = "2021-01-22";
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=";
})
];

src = fetchFromGitHub {
owner = "xiph";
repo = "rnnoise";
rev = "1cbdbcf1283499bbb2230a6b0f126eb9b236defd";
sha256 = "1y0rzgmvy8bf9a431garpm2w177s6ajgf79y5ymw4yb0pik57rwb";
model = fetchurl {
url = model_url;
hash = model_hash;
};

postPatch = ''
tar xvomf ${finalAttrs.model}
'';

nativeBuildInputs = [ autoreconfHook ];

postInstall = ''
install -Dt $out/bin examples/.libs/rnnoise_demo
'';

meta = with lib; {
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 = {
description = "Recurrent neural network for audio noise reduction";
homepage = "https://people.xiph.org/~jm/demo/rnnoise/";
license = licenses.bsd3;
maintainers = [ maintainers.nh2 ];
license = lib.licenses.bsd3;
maintainers = with lib.maintainers; [ nh2 ];
mainProgram = "rnnoise_demo";
platforms = platforms.all;
platforms = lib.platforms.all;
};
})
4 changes: 4 additions & 0 deletions pkgs/development/libraries/rnnoise/model-version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"version": "0b50c45",
"hash": "sha256-SsgcXAiE7EvVkHAmqq4WIJt7ds2df3GvWCCUovmPS0M="
}

0 comments on commit fcd0c62

Please sign in to comment.