Nix expression for creating a derivation of Blender package

Hello guys, I am new (very) Nix user and am trying to write a Nix expression to build the Blender application as a learning exercise. I have seen the blender/default.nix in the github repo to use it as a reference but am struggling with a cmake related issue and dont see anything in the blender/default.nix in github which addresses this (with my very limited understanding).

Problem
I want to install blender with the python-3.10 modules and also numpy and zstd libraries. So I have these in the pythonpath and also buildInputs. The issue however is that cmake is trying to look for numpy, requests and zstd libs in the same path that Python is installed in. For example:

Python package 'numpy' path could not be found in:
/nix/store/9srs642k875z3qdk8glapjycncf2pa51-python3-3.10.7/lib/python3.10/site-packages/numpy
/nix/store/9srs642k875z3qdk8glapjycncf2pa51-python3-3.10.7/lib/python3/site-packages/numpy
/nix/store/9srs642k875z3qdk8glapjycncf2pa51-python3-3.10.7/lib/python3.10/dist-packages/numpy

Python package 'requests' path could not be found in:
/nix/store/9srs642k875z3qdk8glapjycncf2pa51-python3-3.10.7/lib/python3.10/site-packages/requests
/nix/store/9srs642k875z3qdk8glapjycncf2pa51-python3-3.10.7/lib/python3/site-packages/requests

However as each package in Nix gets its own unique path based on the hash, these packages are actually installed somewhere else.

How can I instruct Cmake to look for these packages in specific paths?
I see that the blender/default.nix has pythonPath = [numpy requests zstd] which I have also added in my own expression. However, I cant seem to ask Cmake to look somewhere else for these packages.

Would really appreciate it if someone can have a look at the following nix expression and guide me through the process?

blender.nix

{ pkgs ? import <nixpkgs> {} }:

with pkgs;

let
  packages = rec {
    grid-blender = stdenv.mkDerivation rec {
      pname = "grid-blender";
      version = "3.3.1";
      phases = ["unpackPhase" "buildPhase" "installPhase"];
      enableParallelBuilding = true;

      src = fetchTarball {
        url = "https://github.com/blender/blender/archive/refs/tags/v${version}.tar.gz";
        sha256 = "0qrx41hmw7f85mkvjyvcv8badbrsmmfif632iinjdxc19kg46nib";
      };

      python = python310;
      nativeBuildInputs = [cmake git python pkg-config];
      buildInputs = [libjpeg libpng zstd freetype openimageio2 opencolorio openexr_3
                     embree boost ffmpeg_5 tbb fftw libGL libGLU glew
                     xorg.libX11 xorg.libXi xorg.libXxf86vm xorg.libXrender
                     # Python packages
                     python310Packages.numpy python310Packages.requests
                   ];

      pythonPath = with python310Packages; [numpy requests zstd python];

      postPatch = ''
        rm build_files/cmake/Modules/FindPython.cmake
      '';

      cmakeFlags = [
        "-DWITH_TBB=ON"
        "-DWITH_ALEMBIC=ON"
        "-DWITH_MOD_OCEANSIM=ON"
        "-DWITH_FFTW3=ON"
        "-DWITH_INSTALL_PORTABLE=OFF"
        # Python
        # "-DPYTHON_LIBRARY=${python.libPrefix}"
        # "-DPYTHON_VERSION=${python.pythonVersion}"
        # "-DPYTHON_LIBPATH=${python}/lib"
        "-DWITH_PYTHON_MODULE=OFF"
        "-DWITH_PYTHON_INSTALL_NUMPY=OFF"
        "-DWITH_PYTHON_INSTALL_ZSTANDARD=OFF"
        "-DWITH_PYTHON_SAFETY=ON"
        # OpenGL
        "-DWITH_GL_EGL=ON"
        "-DWITH_GLEW_ES=ON"
        ];


      installPhase = ''
        echo "########################################"
        echo $pythonPath
      '';
    };
  };

in
  packages

Thanks! :grinning:

Looking around, actually found this which works for me.

thanks @d0ntrash :smiley:

python.withPackages