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