How to solve a circular dependency problem when installing python packages by building them with nix?

I’m trying to install DocArray and Jina Hubble SDK using Nix, but I’m encountering a circular dependency issue. Specifically, I need to install DocArray to proceed with the installation of Jina Hubble SDK, but Jina Hubble SDK is a prerequisite for installing DocArray.

flake.nix

{  description = "Python environment with ollama";

 inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";  inputs.flake-utils.url = "github:numtide/flake-utils";

 outputs = { self, nixpkgs, flake-utils, ... }:
    flake-utils.lib.eachDefaultSystem (system: let
      pkgs = nixpkgs.legacyPackages.${system};
      
      #Define Python package jina-hubble-sdk
      jina-hubble-sdk = with pkgs.python3Packages;
        buildPythonPackage rec {
          pname = "jina-hubble-sdk";
          version = "0.39.0";

          src = pkgs.fetchPypi {
            inherit pname version;
            sha256 = "9021417794a6d3cf3fad8a880cf668a3a986b9d53d5be5fa391aae1767a5b9b0";
          };
          preConfigure = ''
            export HOME=$(mktemp -d)
          '';


          nativeBuildInputs = [
            poetry-core
          ];

          propagatedBuildInputs = [
            opentelemetry-instrumentation-grpc
            uvloop
            aiofiles
            websockets
            pep517
            pip
            requests
            aiohttp
            rich
            importlib-metadata
            filelock
            pathspec
            docker
            pyyaml
            python-jose
          ];
        };
      # # Define Python package jcloud
      jcloud = with pkgs.python3Packages;
        buildPythonPackage rec {
          pname = "jcloud";
          version = "0.3";

          src = pkgs.fetchPypi {
            inherit pname version;
            sha256 = "dc062c0454041562476032768fc48f426cc40b8e2323d9626377ff44b0d6f3d9";
          };

          preConfigure = ''
            export HOME=$(mktemp -d)
          '';

          nativeBuildInputs = [
            poetry-core
          ];

          propagatedBuildInputs = [
            pip
            rich
            aiohttp
            jina-hubble-sdk
            packaging
            pyyaml
            python-dotenv
            python-dateutil
            #python-dateutil
            #python-dotenv
            #pyyaml
            # Add any dependencies jcloud might have here
          ];
        };

      # Define Python package jina
      jina = with pkgs.python3Packages;
        buildPythonPackage rec {
          pname = "jina";
          version = "3.24.0";

          src = pkgs.fetchPypi {
            inherit pname version;
            sha256 = "91f7a6141f46884b87d011e64cbf053391d418289391c3c633b10f0c7942553b";
          };

          nativeBuildInputs = [
            poetry-core
          ];

          propagatedBuildInputs = [
            pip
            jcloud
            # Add any dependencies jina might have here
          ];
        };

      # Define Python package docarray
      docarray = with pkgs.python3Packages;
        buildPythonPackage rec {
          pname = "docarray";
          version = "0.40.0";
          format = "pyproject";

          src = pkgs.fetchPypi {
            inherit pname version;
            sha256 = "c3f3b88b7b6128c10308dddbd21650c9845e270da850cf6718cb1d3d867d5986";
          };

          nativeBuildInputs = [
            poetry-core
          ];

          propagatedBuildInputs = [
            numpy
            orjson
            pydantic
            rich
            types-requests
            typing-inspect
          ];
        };

      # Define Python package vectordb
      vectordb = with pkgs.python3Packages;
        buildPythonPackage rec {
          pname = "vectordb";
          version = "0.0.21";

          src = pkgs.fetchPypi {
            inherit pname version;
            sha256 = "3f4857ed3f26dc2384415f28851526037058008156719ca0cfc208a9a02d88e8";
          };

          nativeBuildInputs = [
            poetry-core
          ];

          propagatedBuildInputs = [
            pip
            setuptools
            docarray
            jina
          ];
        };

      # Define Python environment with necessary packages
      pythonEnv = pkgs:
        pkgs.python3.withPackages (ps:
          with ps; [
            langchain-community
            langchainplus-sdk
            langchain
            tiktoken
            docarray
            vectordb
            jina # Include jina in the environment
            jcloud # Include jcloud in the environment
          ]);
    in {
      devShells.default = pkgs.mkShell {
        buildInputs = with pkgs; [
          curl
          ollama
          (pythonEnv pkgs)
        ];
      };
    }); }

If you run the flake after commenting every python package above docarray, you get this error when running the flake:

error:

… while calling the ‘derivationStrict’ builtin

 at /builtin/derivation.nix:9:12: (source not available)

… while evaluating derivation ‘nix-shell’
whose name attribute is located at /nix/store/zaza7mgggz4m5h6z18kajabf4wciaj47-source/pkgs/stdenv/generic/make-derivation.nix:331:7

… while evaluating attribute ‘buildInputs’ of derivation ‘nix-shell’

 at /nix/store/zaza7mgggz4m5h6z18kajabf4wciaj47-source/pkgs/stdenv/generic/make-derivation.nix:378:7:

  377|       depsHostHost                = elemAt (elemAt dependencies 1) 0;
  378|       buildInputs                 = elemAt (elemAt dependencies 1) 1;
     |       ^
  379|       depsTargetTarget            = elemAt (elemAt dependencies 2) 0;

(stack trace truncated; use ‘–show-trace’ to show the full trace)

error: undefined variable ‘jina’

at /nix/store/9z9khfrsm3dx1jh55cw09zi36l6dg1q2-source/flake.nix:162:13:

  161|             vectordb
  162|             jina # Include jina in the environment
     |             ^
  163|             jcloud # Include jcloud in the environment

It means you have to install jcloud. uncomment jcloud. the error message say you have to install another package. Therefore you uncomment more until you uncomment the jina-hubble-sdk package. And you get this error

error: builder for ‘/nix/store/c4xggnbjhl6wj6w71c6nszzxx39iv93a-python3.11-jina-3.24.0.drv’ failed with exit code 1; last 10 log lines: > ir_d = dist.fetch_build_eggs(dist.install_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 0x7ffff55a3cd0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /simple/docarray/ > 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 0x7ffff55b07d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /simple/docarray/ > 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 0x7ffff55b1310>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /simple/docarray/ > 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 0x7ffff55b1e10>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /simple/docarray/ > 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 0x7ffff55b2990>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /simple/docarray/ > ERROR: Could not find a version that satisfies the requirement docarray>=0.16.4 (from versions: none) > ERROR: No matching distribution found for docarray>=0.16.4 > error: Command ‘[’/nix/store/3v2ch16fkl50i85n05h5ckss8pxx6836-python3-3.11.8/bin/python3.11’, ‘-m’, ‘pip’, ‘–disable-pip-version-check’, ‘wheel’, ‘–no-deps’, ‘-w’, ‘/build/tmp0nl2c1kv’, ‘–quiet’, ‘docarray>=0.16.4’]’ returned non-zero exit status 1. For full logs, run ‘nix log /nix/store/c4xggnbjhl6wj6w71c6nszzxx39iv93a-python3.11-jina-3.24.0.drv’. error: 1 dependencies of derivation ‘/nix/store/gw13rrga3q9mfsyly7lksmqpz85b81gd-python3-3.11.8-env.drv’ failed to build error: 1 dependencies of derivation ‘/nix/store/81jdcd1la69iry4f83cgwhim27gvnvsb-nix-shell-env.drv’ failed to build

It means that you have to install docarray. How can solve this circular dependency problem