ERROR Backend 'setuptools.build_meta:__legacy__' is not available

This is also posted on Discord.

This is something of a continuation of this support post.

First off, I’m trying to build a different package (Chapterize-Audiobooks) than the one at hand here. That has a python dependency: vosk. Vosk is not already part of nixpkgs (no pkgs.python3Packages.vosk) so I am trying to build it as a package:

{
    lib,
    pkgs,
    buildPythonPackage,
    fetchFromGitHub,
    ...
}:
buildPythonPackage rec {
    pname = "vosk";
    version = "0.3.50";

    src = fetchFromGitHub {
        owner = "alphacep";
        repo = "vosk-api";
        rev = "v${version}";
        # The easiest way to get the sha256 is to build it and let it fail
        # the error message should include the correct sha256
        sha256 = "sha256-E0Xl+TbI06ArHSk1t6DsXLUlfMQZGKQMTp7smGxgp2Y=";
    };

    doCheck = false;

    pyproject = true;
    buildsystem = with pkgs.python3Packages; [
        setuptools
    ];

    meta = {
        description = ''[this is long]'';
        homepage = "https://github.com/alphacep/vosk-api";
        license = lib.licenses.asl20;
        platforms = lib.platforms.all;
        badPlatforms = [ ];
    };
}

But it isn’t working. I get ERROR Source /nix/var/nix/builds/nix-50774-401767848/source does not appear to be a Python project: no pyproject.toml or setup.py. However, Vosk does have a setup.up just at python/setup.py instead of top-level. In fact, it’s even in PyPi to install via pip. (This isn’t working. Trying

...
src = fetchPyPi {
  inherit pname, version;
  sha-256 = "";
};
...

just gives a bunch of HTTP 404 errors and error: cannot download vosk-0.3.45.tar.gz from any mirror.)

Is there a way I can tell the package to check python/setup.py? Or better yet, an already packaged Vosk I can use in the main build?

I found this forum post that talks about packaging Vosk, but doesn’t really report success: https://discourse.nixos.org/t/vosk-a-python-package-not-in-nixpkgs/71858/3

That was resolved with a neat sourceRoot = "${src.name}/python";

I’m trying to build Vosk for python:

{
    lib,
    pkgs,
    buildPythonPackage,
    fetchFromGitHub,
    ...
}:
buildPythonPackage rec {
    pname = "vosk";
    version = "0.3.50";

    src = fetchFromGitHub {
        owner = "alphacep";
        repo = "vosk-api";
        rev = "v${version}";
        sha256 = "sha256-E0Xl+TbI06ArHSk1t6DsXLUlfMQZGKQMTp7smGxgp2Y=";
    };

    sourceRoot = "${src.name}/python";

    doCheck = false;

    pyproject = true;
    buildsystem = with pkgs.python3Packages; [
        setuptools
        wheel
    ];

    meta = {
        description = "Offline open source speech recognition API based on Kaldi and Vosk";
        homepage = "https://github.com/alphacep/vosk-api";
        license = lib.licenses.asl20;
        platforms = lib.platforms.all;
        badPlatforms = [ ];
    };
}

But I am getting an error that I have no idea what to do with:

> Traceback (most recent call last):
>   File "/nix/store/ggihaikni67b0p8wmw74skjia305lmxb-python3.13-pyproject-hooks-1.2.0/lib/python3.13/site-packages/pyproject_hooks/_impl.py", line 402, in _call_hook
>     raise BackendUnavailable(
>     ...<4 lines>...
>     )
> pyproject_hooks._impl.BackendUnavailable: Cannot import 'setuptools.build_meta'
>
> ERROR Backend 'setuptools.build_meta:__legacy__' is not available.

uh, how can I fix this?

This should be false, the project doesn’t have a pyproject.toml.

But it has a setup.py and is using setuptools, then that one should be true as well. It’s unintuitive, agreed. But it’s how it’s explained in the nixpkgs manual indeed (can’t quote as I’m on mobile).

Though it might be related to the misspelling of build-system (missing hyphen).

1 Like

indeed, I found… a solution by using fetchPypi and specifying the python, dist, platform, and format = “wheel”. (I haven’t finished solving my main problem so it might still break, but nh I think is reporting that it builds.) Is that a thing? That pyproject = true needs a pyproject.toml?

Out of curiosity though, I tried that: get rid of pyproject. Setting format = “setuptools”;, I get this delight of an error log:

Sourcing python-remove-tests-dir-hook
Sourcing python-catch-conflicts-hook.sh
Sourcing python-remove-bin-bytecode-hook.sh
Sourcing setuptools-build-hook
Using setuptoolsBuildPhase Sourcing pypa-install-hook
Using pypaInstallPhase Sourcing python-imports-check-hook.sh
Using pythonImportsCheckPhase Sourcing python-namespaces-hook
Sourcing python-catch-conflicts-hook.sh
Running phase: unpackPhase
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking source archive /nix/store/kvpkg8i1a5h9chzny8dlanj1b6h9ipmb-source
source root is source/python
setting SOURCE_DATE_EPOCH to timestamp 315619200 of file "source/python/vosk_builder.py"
Running phase: patchPhase
@nix { "action": "setPhase", "phase": "patchPhase" }
Running phase: updateAutotoolsGnuConfigScriptsPhase
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
Running phase: configurePhase
@nix { "action": "setPhase", "phase": "configurePhase" }
no configure script, doing nothing 
Running phase: buildPhase @nix { "action": "setPhase", "phase": "buildPhase" }
Executing setuptoolsBuildPhase
setup.py build flags: ''
setup.py:21: DeprecationWarning: The 'wheel.bdist_wheel' module has been removed.
Please update your setuptools to v70.1 or later.
If you're explicitly importing 'wheel.bdist_wheel', please update your import to point to 'setuptools.command.bdist_wheel' instead.

    from wheel.bdist_wheel import bdist_wheel
/nix/store/5yd112f386nb9a35dg8qiwfd9igwmcag-python3.13-setuptools-80.9.0/lib/python3.13/site-packages/setuptools/__init__.py:92: _DeprecatedInstaller: setuptools.installer and fetch_build_eggs are deprecated.
!!

        ********************************************************************************
        Requirements should be satisfied by a PEP 517 installer.
        If you are using pip, you can try `pip install --use-pep517`.

        This deprecation is overdue, please update your project and remove deprecated
        calls to avoid build errors in the future.
        ********************************************************************************
!!
    dist.fetch_build_eggs(dist.setup_requires)
/nix/store/48ak878425b9wyrkwd826d2043m3ii36-python3-3.13.11/bin/python3.13: No module named pip
Traceback (most recent call last):
    File e[35m"/nix/store/5yd112f386nb9a35dg8qiwfd9igwmcag-python3.13-setuptools-80.9.0/lib/python3.13/site-packages/setuptools/installer.py", line 121, in _fetch_build_egg_no_warn 
        subprocess.check_call(cmd)
        ~~~~~~~~~~~~~~~~~~~~~^^^^^
    File "/nix/store/48ak878425b9wyrkwd826d2043m3ii36-python3-3.13.11/lib/python3.13/subprocess.py", line 419, in check_call
        raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/nix/store/48ak878425b9wyrkwd826d2043m3ii36-python3-3.13.11/bin/python3.13', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/nix/var/nix/builds/nix-65702-576578016/tmp6p71smo0', '--quiet', 'cffi>=1.0']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
    File "/nix/var/nix/builds/nix-65702-576578016/source/python/nix_run_setup", line 8, in <module>
        exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))
        ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "setup.py", line 46, in <module>
        setuptools.setup(
        ~~~~~~~~~~~~~~~~^
            name="vosk",
            ^^^^^^^^^^^^
        ...<26 lines>...
            cffi_modules=['vosk_builder.py:ffibuilder'],
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        )
        ^
    File "/nix/store/5yd112f386nb9a35dg8qiwfd9igwmcag-python3.13-setuptools-80.9.0/lib/python3.13/site-packages/setuptools/__init__.py", line 114, in setup
        _install_setup_requires(attrs)
        ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
    File "/nix/store/5yd112f386nb9a35dg8qiwfd9igwmcag-python3.13-setuptools-80.9.0/lib/python3.13/site-packages/setuptools/__init__.py", line 87, in _install_setup_requires
        _fetch_build_eggs(dist)
        ~~~~~~~~~~~~~~~~~^^^^^^
    File "/nix/store/5yd112f386nb9a35dg8qiwfd9igwmcag-python3.13-setuptools-80.9.0/lib/python3.13/site-packages/setuptools/__init__.py", line 92, in _fetch_build_eggs
        dist.fetch_build_eggs(dist.setup_requires)
        ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
    File "/nix/store/5yd112f386nb9a35dg8qiwfd9igwmcag-python3.13-setuptools-80.9.0/lib/python3.13/site-packages/setuptools/dist.py", line 766, in fetch_build_eggs
        return _fetch_build_eggs(self, requires)
    File "/nix/store/5yd112f386nb9a35dg8qiwfd9igwmcag-python3.13-setuptools-80.9.0/lib/python3.13/site-packages/setuptools/installer.py", line 54, in _fetch_build_eggs
        resolved_dists = [_fetch_build_egg_no_warn(dist, req) for req in needed_reqs]
                          ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
    File "/nix/store/5yd112f386nb9a35dg8qiwfd9igwmcag-python3.13-setuptools-80.9.0/lib/python3.13/site-packages/setuptools/installer.py", line 123, in _fetch_build_egg_no_warn
        raise DistutilsError(str(e)) from e
    distutils.errors.DistutilsError: Command '['/nix/store/48ak878425b9wyrkwd826d2043m3ii36-python3-3.13.11/bin/python3.13', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/nix/var/nix/builds/nix-65702-576578016/tmp6p71smo0', '--quiet', 'cffi>=1.0']' returned non-zero exit status 1.

It won’t build without pyproject = true or format being set. and format = “wheel” doesn’t work for… wheel reasons idk:

┃        > Sourcing python-remove-tests-dir-hook
┃        > Sourcing python-catch-conflicts-hook.sh
┃        > Sourcing python-remove-bin-bytecode-hook.sh
┃        > Sourcing wheel setup hook
┃        > Using wheelUnpackPhase
┃        > Sourcing pypa-install-hook
┃        > Using pypaInstallPhase
┃        > Sourcing python-imports-check-hook.sh
┃        > Using pythonImportsCheckPhase
┃        > Sourcing python-namespaces-hook
┃        > Sourcing python-catch-conflicts-hook.sh
┃        > Running phase: unpackPhase
┃        > Executing wheelUnpackPhase
┃        > cp: -r not specified; omitting directory '/nix/store/kvpkg8i1a5h9chzny8dlanj1b6h9ipmb-source'

ooo, that’s a new error! using pyproject = true; and fixing build-system gives

<string>:21: DeprecationWarning: The 'wheel.bdist_wheel' module has been removed.
┃        > Please update your setuptools to v70.1 or later.
┃        > If you're explicitly importing 'wheel.bdist_wheel', please update your import to point to 'setuptools.command.bdist_wheel' instead.
┃        >
┃        >
┃        > ERROR Missing dependencies:
┃        >      requests
┃        >      cffi>=1.0
┃        >      tqdm
┃        >      websockets
┃        >      srt

simply chucking in

    propagatedBuildInputs = with pkgs.python3Packages; [
        cffi
        requests
        srt
        tqdm
        websockets
    ];

seems to do the trick. At least, nh has a check mark next to vosk and is back to complaining about the main problem.