Vosk, a python package not in Nixpkgs

Hello. I need to use this python library that it does not exist as a package

I have read the Python wiki and I understand how to add nixpkgs-existing libraries but I do not understand the section:

Using a Python package not in Nixpkgs

Developing with python

I read so many times. I wrote this:

{
  lib,
  buildPythonPackage,
  fetchPypi,
  setuptools,
}:

buildPythonPackage rec {
  pname = "vosk";
  version = "0.3.45";
  format = "wheel";

  src = fetchPypi {
    inherit pname version;
    hash = "15x6zw9hn9l2irm7fljch23965kgs6n0kgaczw03mks29h232glh";
  };

  build-system = [ setuptools ];

  # has no tests
  doCheck = false;

#  pythonImportsCheck = [
#    "toolz.itertoolz"
#    "toolz.functoolz"
#    "toolz.dicttoolz"
#  ];

  meta = {
    changelog = "https://alphacephei.com/vosk/";
    homepage = "https://github.com/alphacep/vosk-api";
    description = "List processing tools and functional utilities";
    license = "Apache Software License";
    author = "Alpha Cephei Inc";
  };
}

And then nixpkg.overlay in my configuration.nix
But it says the hash is incorrect. Might be true. I do not know how to do this. I just want to use python and its available libraries but I am going down a rabbit hole. Maybe I can try NOT using wheels and use the compilation from source(?. But still. I do not know if I am putting the right hash. I am just using nix-prefetch-url (url provided in vosk homepage) to get the hash.

Don’t waste time with prefetch scripts.
Just set the hash to "" (exactly the empty string, do not use anything else) and build and use the “expected” hash from the error.

Also format is deprecated, you’re better off setting pyproject as per the manual: https://nixos.org/manual/nixpkgs/unstable/#python

EDIT: seems like someone is already trying to package this for nixpkgs in Add Vosk offline speech recognition service by sbruder · Pull Request #186917 · NixOS/nixpkgs · GitHub. Maybe you’ll find their work helpful.

1 Like

Ok. So I read the manual again and walked through the process. I will be using a nix-shell for easier testing. The only thing I’m missing is the (hash). How do I get that? Am I getting the right one?

If I leave it empty it says ERROR 404.

shell.nix

maximo@nixos:~/1.dev/python/toolz/ > cat shell.nix 
with import <nixpkgs> { };

(
  let
    my_vosk = python313.pkgs.buildPythonPackage rec {
      pname = "vosk";
      version = "0.3.45";
      pyproject = true;

      src = fetchPypi {
        inherit pname version;
        hash = "sha256-25e025093c4399d7278f543568ed8cc5460ac3a4bf48c23673ace1e25d26619f";
      };

      build-system = [ python313.pkgs.setuptools ];

      # has no tests
      doCheck = false;

      meta = {
        homepage = "https://github.com/pytoolz/toolz/";
        description = "List processing tools and functional utilities";
        # [...]
      };
    };

  in
  python313.withPackages (
    ps: with ps; [
      numpy
      my_vosk
    ]
  )
).env

Excuse the softness of my brain but I do not understand anything in that pull request. I just want to add a python package in nixos. Thank you of course for the reply.

That means the file is not available, then. Setting a hash won’t help you, you have to fetch a file that exists. The pull request I linked uses fetchFromGitHub instead.

Scroll down to pkgs/tools/audio/vosk/default.nix‎. If you need the python module, then pkgs/development/python-modules/vosk/default.nix‎. Note that some of the files in the PR end up depending on each other.

Of course the PR is kind of old, so it’s possible that the build process is different now.

1 Like