Poetry2nix html5tagger

Hi! I am trying to package a python project with poetry2nix. I needed to add setuptools as a dependency to the html5tagger python package, as described in the poetry2nix edge cases.

When I try and start a nix development shell I get error: metadata-generation-failed. Here are the full logs

 Sourcing python-remove-tests-dir-hook
Sourcing python-catch-conflicts-hook.sh
Sourcing python-remove-bin-bytecode-hook.sh
Sourcing pip-install-hook
Using pipInstallPhase
Sourcing python-imports-check-hook.sh
Using pythonImportsCheckPhase
Sourcing python-namespaces-hook
Sourcing pip-build-hook
Using pipBuildPhase
Using pipShellHook
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/yb2x5wjmpa2ksrdnyzavq0jq90z0wjhc-html5tagger-1.3.0.tar.gz
source root is html5tagger-1.3.0
setting SOURCE_DATE_EPOCH to timestamp 1679983171 of file html5tagger-1.3.0/setup.cfg
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
no configure script, doing nothing
@nix { "action": "setPhase", "phase": "buildPhase" }
building
Executing pipBuildPhase
Creating a wheel...
WARNING: The directory '/homeless-shelter/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo's -H flag.
Processing /build/html5tagger-1.3.0
  Running command python setup.py egg_info
  /nix/store/hxqf8h7yq8d8nchhkac9lqihdqj9h0ml-python3.10-setuptools-67.4.0/lib/python3.10/site-packages/setuptools/__init__.py:85: _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`.
    dist.fetch_build_eggs(dist.setup_requires)
  WARNING: The directory '/homeless-shelter/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo's -H flag.
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7ffff57de9b0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/setuptools-scm/
  WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7ffff57dec80>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/setuptools-scm/
  WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7ffff57dee30>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/setuptools-scm/
  WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7ffff57defe0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/setuptools-scm/
  WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7ffff57df190>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/setuptools-scm/
  ERROR: Could not find a version that satisfies the requirement setuptools_scm (from versions: none)
  ERROR: No matching distribution found for setuptools_scm
  Traceback (most recent call last):
    File "/nix/store/hxqf8h7yq8d8nchhkac9lqihdqj9h0ml-python3.10-setuptools-67.4.0/lib/python3.10/site-packages/setuptools/installer.py", line 97, in _fetch_build_egg_no_warn
      subprocess.check_call(cmd)
    File "/nix/store/bc45k1n0pkrdkr3xa6w84w1xhkl1kkyp-python3-3.10.12/lib/python3.10/subprocess.py", line 369, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['/nix/store/bc45k1n0pkrdkr3xa6w84w1xhkl1kkyp-python3-3.10.12/bin/python3.10', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/build/tmpf_pcopfi', '--quiet', 'setuptools_scm']' returned non-zero exit status 1.

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

  Traceback (most recent call last):
    File "<string>", line 2, in <module>
    File "<pip-setuptools-caller>", line 34, in <module>
    File "/build/html5tagger-1.3.0/setup.py", line 3, in <module>
      setup(
    File "/nix/store/hxqf8h7yq8d8nchhkac9lqihdqj9h0ml-python3.10-setuptools-67.4.0/lib/python3.10/site-packages/setuptools/__init__.py", line 107, in setup
      _install_setup_requires(attrs)
    File "/nix/store/hxqf8h7yq8d8nchhkac9lqihdqj9h0ml-python3.10-setuptools-67.4.0/lib/python3.10/site-packages/setuptools/__init__.py", line 80, in _install_setup_requires
      _fetch_build_eggs(dist)
    File "/nix/store/hxqf8h7yq8d8nchhkac9lqihdqj9h0ml-python3.10-setuptools-67.4.0/lib/python3.10/site-packages/setuptools/__init__.py", line 85, in _fetch_build_eggs
      dist.fetch_build_eggs(dist.setup_requires)
    File "/nix/store/hxqf8h7yq8d8nchhkac9lqihdqj9h0ml-python3.10-setuptools-67.4.0/lib/python3.10/site-packages/setuptools/dist.py", line 894, in fetch_build_eggs
      return _fetch_build_eggs(self, requires)
    File "/nix/store/hxqf8h7yq8d8nchhkac9lqihdqj9h0ml-python3.10-setuptools-67.4.0/lib/python3.10/site-packages/setuptools/installer.py", line 39, in _fetch_build_eggs
      resolved_dists = pkg_resources.working_set.resolve(
    File "/nix/store/hxqf8h7yq8d8nchhkac9lqihdqj9h0ml-python3.10-setuptools-67.4.0/lib/python3.10/site-packages/pkg_resources/__init__.py", line 815, in resolve
      dist = self._resolve_dist(
    File "/nix/store/hxqf8h7yq8d8nchhkac9lqihdqj9h0ml-python3.10-setuptools-67.4.0/lib/python3.10/site-packages/pkg_resources/__init__.py", line 851, in _resolve_dist
      dist = best[req.key] = env.best_match(
    File "/nix/store/hxqf8h7yq8d8nchhkac9lqihdqj9h0ml-python3.10-setuptools-67.4.0/lib/python3.10/site-packages/pkg_resources/__init__.py", line 1123, in best_match
      return self.obtain(req, installer)
    File "/nix/store/hxqf8h7yq8d8nchhkac9lqihdqj9h0ml-python3.10-setuptools-67.4.0/lib/python3.10/site-packages/pkg_resources/__init__.py", line 1135, in obtain
      return installer(requirement)
    File "/nix/store/hxqf8h7yq8d8nchhkac9lqihdqj9h0ml-python3.10-setuptools-67.4.0/lib/python3.10/site-packages/setuptools/installer.py", line 99, in _fetch_build_egg_no_warn
      raise DistutilsError(str(e)) from e
  distutils.errors.DistutilsError: Command '['/nix/store/bc45k1n0pkrdkr3xa6w84w1xhkl1kkyp-python3-3.10.12/bin/python3.10', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/build/tmpf_pcopfi', '--quiet', 'setuptools_scm']' returned non-zero exit status 1.
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: /nix/store/bc45k1n0pkrdkr3xa6w84w1xhkl1kkyp-python3-3.10.12/bin/python3.10 -c '
  exec(compile('"'"''"'"''"'"'
  # This is <pip-setuptools-caller> -- a caller that pip uses to run setup.py
  #
  # - It imports setuptools before invoking setup.py, to enable projects that directly
  #   import from `distutils.core` to work with newer packaging standards.
  # - It provides a clear error message when setuptools is not installed.
  # - It sets `sys.argv[0]` to the underlying `setup.py`, when invoking `setup.py` so
  #   setuptools doesn'"'"'t think the script is `-c`. This avoids the following warning:
  #     manifest_maker: standard file '"'"'-c'"'"' not found".
  # - It generates a shim setup.py, for handling setup.cfg-only projects.
  import os, sys, tokenize
  
  try:
      import setuptools
  except ImportError as error:
      print(
          "ERROR: Can not execute `setup.py` since setuptools is not available in "
          "the build environment.",
          file=sys.stderr,
      )
      sys.exit(1)
  
  __file__ = %r
  sys.argv[0] = __file__
  
  if os.path.exists(__file__):
      filename = __file__
      with tokenize.open(__file__) as f:
          setup_py_code = f.read()
  else:
      filename = "<auto-generated setuptools caller>"
      setup_py_code = "from setuptools import setup; setup()"
  
  exec(compile(setup_py_code, filename, "exec"))
  '"'"''"'"''"'"' % ('"'"'/build/html5tagger-1.3.0/setup.py'"'"',), "<pip-setuptools-caller>", "exec"))' egg_info --egg-base /build/pip-pip-egg-info-4f4gvdu1
  cwd: /build/html5tagger-1.3.0/
  Preparing metadata (setup.py) ... e[?25le[?25herror
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Here is my flake.nix

{
  description = "Nix python example";
  inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";

  inputs.poetry2nix = {
    url = "github:nix-community/poetry2nix";
    inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = { self, nixpkgs, flake-utils, poetry2nix }:
  let
        poetry_env = (mkPoetryPackages {
          projectDir = ./.;
          overrides = defaultPoetryOverrides.extend
            (self: super: {
              html5tagger = super.html5tagger.overridePythonAttrs
                (
                  old: {
                    buildInputs = (old.buildInputs or [ ]) ++ [ super.setuptools super.hatchling super.setuptools_scm];
                  }
                );
              aiofiles = super.aiofiles.overridePythonAttrs
                (
                  old: {
                    buildInputs = (old.buildInputs or [ ]) ++ [ super.hatchling super.setuptools];
                  }
                );
            });
        });
        inherit (poetry2nix.legacyPackages."x86_64-linux") mkPoetryApplication mkPoetryEnv mkPoetryEditablePackage mkPoetryPackages defaultPoetryOverrides;
        x86_pkgs = nixpkgs.legacyPackages."x86_64-linux";
  in
{
      packages."x86_64-linux" = {
        myapp = mkPoetryApplication { projectDir = self; };
        default = self.packages."x86_64-linux".myapp;
      };
      # Devshells
      devShells."x86_64-linux" = {
        # Normal devshell that is auto activated by direnv when entering this
        # repos directory. Contains useful tools for nix developments and for
        # the languages used in my dotfiles.
        default = x86_pkgs.mkShell {
          #inherit (pre-commit-check) shellHook; #TODO:. setup precommit?
          packages = with x86_pkgs; [
            # nil
            # nixpkgs-fmt
            # python3Packages.python-lsp-server
            # python3Packages.flake8
            # black
            # poetry2nix.packages."x86_64-linux".poetry
            poetry_env.python
          ] ++ poetry_env.poetryPackages;
        };
      };
  };
}

It appears like python is trying to reach the internet but fails to do so (which the nix sandbox should do right?) Any good ideas how to fix? Tried adding setuptools to other packages as well but did not work. When I google the errors, I have not been able to find anything useful.