at master 2.5 kB view raw
1{ 2 lib, 3 stdenv, 4 buildPythonPackage, 5 fetchPypi, 6 7 # nativeBuildInputs 8 cmake, 9 10 # build-system 11 setuptools, 12 13 # buildInputs 14 mujoco, 15 pybind11, 16 17 # dependencies 18 absl-py, 19 etils, 20 glfw, 21 numpy, 22 pyopengl, 23 typing-extensions, 24 25 perl, 26 python, 27}: 28 29buildPythonPackage rec { 30 pname = "mujoco"; 31 inherit (mujoco) version; 32 33 pyproject = true; 34 35 # We do not fetch from the repository because the PyPi tarball is 36 # impurely build via 37 # <https://github.com/google-deepmind/mujoco/blob/main/python/make_sdist.sh> 38 # in the project's CI. 39 src = fetchPypi { 40 inherit pname version; 41 hash = "sha256-Emv7DbRC62QHd23E+Yx8AilUlHkx4Dw5XsRfpYRj+14="; 42 }; 43 44 nativeBuildInputs = [ cmake ]; 45 46 dontUseCmakeConfigure = true; 47 48 build-system = [ setuptools ]; 49 50 buildInputs = [ 51 mujoco 52 pybind11 53 ]; 54 55 dependencies = [ 56 absl-py 57 etils 58 glfw 59 numpy 60 pyopengl 61 typing-extensions 62 ]; 63 64 pythonImportsCheck = [ "${pname}" ]; 65 66 env.MUJOCO_PATH = "${mujoco}"; 67 env.MUJOCO_PLUGIN_PATH = "${mujoco}/lib"; 68 env.MUJOCO_CMAKE_ARGS = lib.concatStringsSep " " [ 69 (lib.cmakeBool "MUJOCO_SIMULATE_USE_SYSTEM_GLFW" true) 70 (lib.cmakeBool "MUJOCO_PYTHON_USE_SYSTEM_PYBIND11" true) 71 ]; 72 73 preConfigure = 74 # Use non-system eigen3, lodepng, abseil: Remove mirror info and prefill 75 # dependency directory. $build from setuptools. 76 ( 77 let 78 # E.g. 3.11.2 -> "311" 79 pythonVersionMajorMinor = 80 with lib.versions; 81 "${major python.pythonVersion}${minor python.pythonVersion}"; 82 83 # E.g. "linux-aarch64" 84 platform = with stdenv.hostPlatform.parsed; "${kernel.name}-${cpu.name}"; 85 in 86 '' 87 ${lib.getExe perl} -0777 -i -pe "s/GIT_REPO\n.*\n.*GIT_TAG\n.*\n//gm" mujoco/CMakeLists.txt 88 ${lib.getExe perl} -0777 -i -pe "s/(FetchContent_Declare\(\n.*lodepng\n.*)(GIT_REPO.*\n.*GIT_TAG.*\n)(.*\))/\1\3/gm" mujoco/simulate/CMakeLists.txt 89 90 build="/build/${pname}-${version}/build/temp.${platform}-cpython-${pythonVersionMajorMinor}/" 91 mkdir -p $build/_deps 92 ln -s ${mujoco.pin.lodepng} $build/_deps/lodepng-src 93 ln -s ${mujoco.pin.eigen3} $build/_deps/eigen-src 94 ln -s ${mujoco.pin.abseil-cpp} $build/_deps/abseil-cpp-src 95 '' 96 ); 97 98 meta = { 99 description = "Python bindings for MuJoCo: a general purpose physics simulator"; 100 inherit (mujoco.meta) homepage changelog license; 101 maintainers = with lib.maintainers; [ 102 GaetanLepage 103 tmplt 104 ]; 105 }; 106}