Use custom python package in complex C++ project

I want to wrap complex C++ framework userver to nix package.

This project is CMake based and in configurePhase it is set local virtual env for functional testing part.

In this virtual env cmake try to install yandex-taxi-testsuite. This package exist on pypi but not in the nixpkgs, so i built it as nix pkgs via buildPythonPackage.

There is nix files:

default.nix

{
  system ? builtins.currentSystem,
}:
let
  pkgs = import <nixpkgs> { inherit system; };
in
  pkgs.callPackage ./userver.nix {}

pythonLibs.nix:

{
lib,
fetchPypi,
python313Packages,
}:
let
  pythonPackages = python313Packages;
in
  rec {
  pytest-runner =
    let
      pname = "pytest-runner";
      version = "6.0.1";
    in
      pythonPackages.buildPythonPackage {
	inherit pname version;
	src = fetchPypi {
	  inherit pname version;
	  sha256 = "cNRzlYWnAI83v0kzwBP9sye4h4paafy7MxbIiILw9Js=";
	};
	pyproject = true;
	build-system = with pythonPackages; [ setuptools-scm ];
  };

  yataxi-testsuite =
    let
      pname = "yandex-taxi-testsuite";
      version = "0.4.5";
    in
      pythonPackages.buildPythonPackage {
	inherit pname version;
	src = fetchPypi {
	  inherit version;
	  pname = (lib.replaceString "-" "_" pname);
	  sha256 = "OrTvWO6I2ghCdL79XsUUY8E/vg8H6bwUmk5PnwPF3Ok=";
	};
	pyproject = true;
	build-system = with pythonPackages; [ setuptools ];
	buildInputs = with pythonPackages; [
	  pytest-runner
	  pyyaml
	  aiohttp
	  yarl
	  py
	  pytest-aiohttp
	  pytest
	  dateutils
	  cached-property
	];
  };
}

userver.nix

{
pkgs,
callPackage,
stdenv,
fetchFromGitHub,
}:
let 
  customPythonPackages = callPackage ./pythonLibs.nix {};
in
  stdenv.mkDerivation {
    pname = "userver-lib";
    version = "3.0";
    src = fetchFromGitHub {
      owner = "userver-framework";
      repo = "userver";
      rev = "v3.0";
      sha256 = "uI91z2pSIoc3Az/N4dwsmkFb7gcFGKx39cHmkPIhpOE=";
    };

    cmakeFlags = [
      "-DUSERVER_DOWNLOAD_PACKAGES=OFF"
      "-DUSERVER_CHECK_PACKAGE_VERSIONS=0"
      "-DUSERVER_PIP_USE_SYSTEM_PACKAGES=ON"
    ];

    nativeBuildInputs = with pkgs; [
      cmake
      yaml-cpp
      zstd
      cryptopp
      fmt_11
      cctz
      jemalloc
      re2
    ];

    buildInputs = with pkgs; [
      openssl_4_0
      boost186
      gtest
      (python313.withPackages (
	    ps: with ps; [
	    pip
	    virtualenv
	    customPythonPackages.yataxi-testsuite
	  ]
    ))
      gbenchmark
    ];
}

in configure phase cmake create virtual env and trying to install yandex-taxi-testsuite via network however it is already installed:

$ nix-shell -E '(import <nixpkgs> {system="x86_64-linux";}).callPackage ./userver.nix {}'

[nix-shell:~/temp]$ pip list -v
Package               Version Location                                                                                     Installer
--------------------- ------- -------------------------------------------------------------------------------------------- ---------
distlib               0.4.0   /nix/store/z7j6xbhw0kppf07w6gr4sdgjy38jap8g-python3-3.13.12-env/lib/python3.13/site-packages
filelock              3.20.3  /nix/store/z7j6xbhw0kppf07w6gr4sdgjy38jap8g-python3-3.13.12-env/lib/python3.13/site-packages
pip                   25.0.1  /nix/store/z7j6xbhw0kppf07w6gr4sdgjy38jap8g-python3-3.13.12-env/lib/python3.13/site-packages
platformdirs          4.5.0   /nix/store/z7j6xbhw0kppf07w6gr4sdgjy38jap8g-python3-3.13.12-env/lib/python3.13/site-packages
virtualenv            20.33.1 /nix/store/z7j6xbhw0kppf07w6gr4sdgjy38jap8g-python3-3.13.12-env/lib/python3.13/site-packages
yandex-taxi-testsuite 0.4.5   /nix/store/z7j6xbhw0kppf07w6gr4sdgjy38jap8g-python3-3.13.12-env/lib/python3.13/site-packages


Problem is that i can’t change behaviour of this virtual env because it is part of cmake configure phase. Here is full build log:

this derivation will be built:
  /nix/store/2mfsph3zyb82ia6qwfyksw5jl0lla625-userver-lib-3.0.drv
building '/nix/store/2mfsph3zyb82ia6qwfyksw5jl0lla625-userver-lib-3.0.drv'...
Running phase: unpackPhase
unpacking source archive /nix/store/jz942hy5c0q6qfgxmsvmfcm81hz027zp-source
source root is source
Running phase: patchPhase
Running phase: updateAutotoolsGnuConfigScriptsPhase
Running phase: configurePhase
cmake flags: -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DCMAKE_INSTALL_LOCALEDIR=/nix/store/xada3hakwalp0bijskd2id0dpm7382im-userver-lib-3.0/share/locale -DCMAKE_INSTALL_LIBEXECDIR=/nix/store/xada3hakwalp0bijskd2id0dpm7382im-userver-lib-3.0/libexec -DCMAKE_INSTALL_LIBDIR=/nix/store/xada3hakwalp0bijskd2id0dpm7382im-userver-lib-3.0/lib -DCMAKE_INSTALL_DOCDIR=/nix/store/xada3hakwalp0bijskd2id0dpm7382im-userver-lib-3.0/share/doc/userver -DCMAKE_INSTALL_INFODIR=/nix/store/xada3hakwalp0bijskd2id0dpm7382im-userver-lib-3.0/share/info -DCMAKE_INSTALL_MANDIR=/nix/store/xada3hakwalp0bijskd2id0dpm7382im-userver-lib-3.0/share/man -DCMAKE_INSTALL_INCLUDEDIR=/nix/store/xada3hakwalp0bijskd2id0dpm7382im-userver-lib-3.0/include -DCMAKE_INSTALL_SBINDIR=/nix/store/xada3hakwalp0bijskd2id0dpm7382im-userver-lib-3.0/sbin -DCMAKE_INSTALL_BINDIR=/nix/store/xada3hakwalp0bijskd2id0dpm7382im-userver-lib-3.0/bin -DCMAKE_INSTALL_NAME_DIR=/nix/store/xada3hakwalp0bijskd2id0dpm7382im-userver-lib-3.0/lib -DCMAKE_STRIP=/nix/store/8v97ngkcpfzgghwnnr7fsz33p2x22gy9-gcc-wrapper-14.3.0/bin/strip -DCMAKE_RANLIB=/nix/store/8v97ngkcpfzgghwnnr7fsz33p2x22gy9-gcc-wrapper-14.3.0/bin/ranlib -DCMAKE_AR=/nix/store/8v97ngkcpfzgghwnnr7fsz33p2x22gy9-gcc-wrapper-14.3.0/bin/ar -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_INSTALL_PREFIX=/nix/store/xada3hakwalp0bijskd2id0dpm7382im-userver-lib-3.0 -DUSERVER_DOWNLOAD_PACKAGES=OFF -DUSERVER_CHECK_PACKAGE_VERSIONS=0 -DUSERVER_PIP_USE_SYSTEM_PACKAGES=ON
-- The CXX compiler identification is GNU 14.3.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /nix/store/8v97ngkcpfzgghwnnr7fsz33p2x22gy9-gcc-wrapper-14.3.0/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Building utest with gtest and ubench with gbench
-- rseq-based acceleration is enabled by default
-- Modules type search priority order: .so;.a (Default ordered)
-- C compiler: gcc
-- C++ compiler: /nix/store/8v97ngkcpfzgghwnnr7fsz33p2x22gy9-gcc-wrapper-14.3.0/bin/g++
-- C++ standard 20
-- Using the default system linker, probably GNU ld
-- LTO: disabled (user request)
-- Performing Test LINKER_HAS_ZSTD
-- Performing Test LINKER_HAS_ZSTD - Failed
-- Performing Test LINKER_HAS_GZ
-- Performing Test LINKER_HAS_GZ - Success
-- Using linker debug info compression: z
-- Performing Test HAS_gz_zstd
-- Performing Test HAS_gz_zstd - Success
-- Checking -gz=zstd - found
-- Using compiler debug info compression: zstd
-- Linker global flags:  -Wl,--gc-sections
-- ccache: enabled, but not found
-- Release build: CMAKE_BUILD_TYPE == 'Release'
-- Could NOT find Git (missing: GIT_EXECUTABLE) 
-- Git not found
-- Python: python3
-- Found OpenSSL: /nix/store/9xc19q5pmpxp993k13ig6bbhzdnnjdfb-openssl-4.0.0/lib/libcrypto.so (found version "4.0.0")
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Could NOT find boost_stacktrace_backtrace (missing: boost_stacktrace_backtrace_DIR)
-- Could NOT find boost_stacktrace_windbg (missing: boost_stacktrace_windbg_DIR)
-- Could NOT find boost_coroutine2 (missing: boost_coroutine2_DIR)
-- Could NOT find boost_config (missing: boost_config_DIR)
-- Could NOT find boost_assert (missing: boost_assert_DIR)
-- Setting up the venv at /build/source/build/venv-utest
-- Installing requirements:
--   /build/source/build/requirements-userver-testsuite.txt
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 0x7ffff5695160>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/wheel/
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 0x7ffff581de50>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/wheel/
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 0x7ffff581e0d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/wheel/
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 0x7ffff581e350>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/wheel/
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 0x7ffff581e5d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/wheel/
ERROR: Could not find a version that satisfies the requirement wheel (from versions: none)
ERROR: No matching distribution found for wheel
CMake Error at cmake/UserverVenv.cmake:169 (message):
  Failed to install venv requirements
Call Stack (most recent call first):
  cmake/UserverTestsuite.cmake:42 (userver_venv_setup)
  cmake/UserverTestsuite.cmake:532 (_userver_prepare_testsuite)
  CMakeLists.txt:243 (include)


-- Configuring incomplete, errors occurred!
error: Cannot build '/nix/store/2mfsph3zyb82ia6qwfyksw5jl0lla625-userver-lib-3.0.drv'.
       Reason: builder failed with exit code 1.
       Output paths:
         /nix/store/xada3hakwalp0bijskd2id0dpm7382im-userver-lib-3.0
       Last 25 log lines:
       > -- Could NOT find boost_stacktrace_backtrace (missing: boost_stacktrace_backtrace_DIR)
       > -- Could NOT find boost_stacktrace_windbg (missing: boost_stacktrace_windbg_DIR)
       > -- Could NOT find boost_coroutine2 (missing: boost_coroutine2_DIR)
       > -- Could NOT find boost_config (missing: boost_config_DIR)
       > -- Could NOT find boost_assert (missing: boost_assert_DIR)
       > -- Setting up the venv at /build/source/build/venv-utest
       > -- Installing requirements:
       > --   /build/source/build/requirements-userver-testsuite.txt
       > 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 0x7ffff5695160>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/wheel/
       > 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 0x7ffff581de50>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/wheel/
       > 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 0x7ffff581e0d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/wheel/
       > 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 0x7ffff581e350>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/wheel/
       > 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 0x7ffff581e5d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/wheel/
       > ERROR: Could not find a version that satisfies the requirement wheel (from versions: none)
       > ERROR: No matching distribution found for wheel
       > CMake Error at cmake/UserverVenv.cmake:169 (message):
       >   Failed to install venv requirements
       > Call Stack (most recent call first):
       >   cmake/UserverTestsuite.cmake:42 (userver_venv_setup)
       >   cmake/UserverTestsuite.cmake:532 (_userver_prepare_testsuite)
       >   CMakeLists.txt:243 (include)
       >
       > 
       > -- Configuring incomplete, errors occurred!
       For full logs, run:
         nix log /nix/store/2mfsph3zyb82ia6qwfyksw5jl0lla625-userver-lib-3.0.drv

There interesting part in log: 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.

It seems like python packages not available and pip try to download them.

I will glad to get any help or directions to research

I found solution. I was need to add “-DUSERVER_PIP_OPTIONS=–no-index” to pass –no-index flag to pip to prevent pip from work with network