From f3ab2984ea2911848a387eee44f3254839d8af02 Mon Sep 17 00:00:00 2001 From: Arnaud TANGUY Date: Tue, 2 Jun 2026 13:25:41 +0200 Subject: [PATCH 1/4] python: add cython bindings for spacevecalg --- README.md | 6 +-- module.nix | 3 +- overlay.nix | 17 ++++++- pkgs/eigen3-to-python/default.nix | 80 +++++++++++++++++++++++++++++++ pkgs/rbdyn/default.nix | 17 ++++--- pkgs/spacevecalg/default.nix | 28 +++++++---- py-pkgs/eigen3-to-python.nix | 9 ++++ py-pkgs/spacevecalg.nix | 9 ++++ 8 files changed, 145 insertions(+), 24 deletions(-) create mode 100644 pkgs/eigen3-to-python/default.nix create mode 100644 py-pkgs/eigen3-to-python.nix create mode 100644 py-pkgs/spacevecalg.nix diff --git a/README.md b/README.md index 01c5da4..9aafd23 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Current status: Allows to build mc-rtc and configure its runtime dependencies (`robots`, `controllers`, `observers`, `plugins`) - [x] Run `MCFrankaControl` with real Panda robots - [x] `mc-rtc-magnum` support (with older `glfw/imgui/implot` as submodules, as done in `mc-rtc-superbuild`) -- [ ] Robots - all most commonly used robots are supported: +- [x] Robots - all most commonly used robots are supported: - [x] JVRC1 - [x] HRP-2Kai - [x] HRP-4 @@ -24,9 +24,9 @@ Current status: - [ ] UR10 - [ ] Controllers - [x] Rolkneematics `panda-prosthesis` (through downstream flake in `panda-prosthesis` repository) - - [ ] WIP: Hugo's polytopeController + - [x] Hugo's polytopeController - [ ] `mc-mujoco`: building and running but some HiDPI scaling issues on Wayland with glfw 3.4 -- [ ] magnum packaging (external): in progress +- [x] magnum packaging - [x] magnum - [x] SDL2Application: works - [x] GlfwApplication: diff --git a/module.nix b/module.nix index 4ebe1b7..288cb64 100644 --- a/module.nix +++ b/module.nix @@ -14,7 +14,7 @@ let rawOverlays = [ { name = "mc-rtc-pkgs"; - value = import ./overlay.nix { inherit with-ros; }; + value = import ./overlay.nix { inherit lib with-ros; }; } ] ++ (lib.optional enablePrivateOverlay { @@ -69,6 +69,7 @@ in // { # Main dependencies inherit (pkgs) + eigen3-to-python spacevecalg rbdyn sch-core diff --git a/overlay.nix b/overlay.nix index 2612b0a..187d217 100644 --- a/overlay.nix +++ b/overlay.nix @@ -6,6 +6,7 @@ Use this to access and override existing packages, or to call functions from the underlying package set. */ { + lib, with-ros ? false, ... }: @@ -45,6 +46,7 @@ ''; }); + eigen3-to-python = prev.callPackage ./pkgs/eigen3-to-python { }; spacevecalg = prev.callPackage ./pkgs/spacevecalg { }; rbdyn = prev.callPackage ./pkgs/rbdyn { }; eigen-qld = prev.callPackage ./pkgs/eigen-qld { }; @@ -221,7 +223,7 @@ # This is not per-say recomended, but it can drastically reduce build time for these components, and also allow for seamless LSP integration in your editor. # # TODO: investigate use of ccacheStdenv - # mc-rtc-superbuild = prev.callPackage ./pkgs/mc-rtc/mc-rtc-superbuild-symlinkjoin.nix.nix { + # mc-rtc-superbuild = prev.callPackage ./pkgs/mc-rtc/mc-rtc-superbuild-symlinkjoin.nix.nix # minimal superbuild environment (jvrc1, mc_rtc_ticker) mc-rtc-superbuild-minimal = prev.callPackage ./pkgs/mc-rtc/mc-rtc-superbuild-standalone.nix { @@ -265,5 +267,18 @@ }; sphinx-cmake = prev.callPackage ./pkgs/sphinx-cmake.nix { }; + + pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [ + ( + python-final: _python-prev: + { + # custom overrides would go here see gepetto/nix for examples + } + // lib.filesystem.packagesFromDirectoryRecursive { + inherit (python-final) callPackage; + directory = ./py-pkgs; + } + ) + ]; } ) diff --git a/pkgs/eigen3-to-python/default.nix b/pkgs/eigen3-to-python/default.nix new file mode 100644 index 0000000..006cbf1 --- /dev/null +++ b/pkgs/eigen3-to-python/default.nix @@ -0,0 +1,80 @@ +{ + stdenv, + lib, + cmake, + pkg-config, + eigen, + fetchFromGitHub, + python3Packages, +}: + +stdenv.mkDerivation { + pname = "eigen3-to-python"; + version = "1.0.7"; + + # pr 35 + src = fetchFromGitHub { + owner = "Kooolkimooov"; + repo = "Eigen3ToPython"; + rev = "a1dfb35c204b2732d0b60d4d2bb6edb4c6941f59"; + hash = "sha256-zNaMmaexyDBD2frMkO4z+Qj/AKtIxt6sRdwYcwoNJh8="; + }; + + nativeBuildInputs = [ + cmake + pkg-config + python3Packages.cython + python3Packages.python + python3Packages.distutils + python3Packages.pytest + python3Packages.pip + ]; + + propagatedBuildInputs = [ + eigen + python3Packages.numpy + ]; + + cmakeFlags = [ + "-DPIP_INSTALL_PREFIX=$out/lib/python3" + "-DCMAKE_BUILD_TYPE=Release" + "-DCYTHON_USE_CACHE=OFF" + ]; + + # Force pip to ignore the EXTERNALLY-MANAGED restriction in the sandbox + PIP_BREAK_SYSTEM_PACKAGES = 1; + # Force pip to use the Nix-provided python packages instead of checking PyPI + PIP_NO_BUILD_ISOLATION = 1; + + # Force Cython/Python to use the build directory for caching instead of /homeless-shelter + preBuild = '' + export HOME=$TMPDIR + ''; + + doCheck = true; + + # Override the default CMake install step + installPhase = '' + runHook preInstall + + # 1. Define the destination directory inside the Nix store output + # Using python.sitePackages handles the "lib/python3.13/site-packages" string automatically + local targetDir="$out/${python3Packages.python.sitePackages}/eigen" + mkdir -p "$targetDir" + + ls -lR + + # 2. Copy your built files from the build tree to the target store path + # (Adjust 'build/python/Release/eigen/' path if your build folder structure differs slightly) + cp -r python/Release/eigen/* "$targetDir" + + runHook postInstall + ''; + + meta = with lib; { + description = "Provide Eigen3 to numpy conversion"; + homepage = "https://github.com/jrl-umi3218/Eigen3ToPython"; + license = licenses.bsd2; + platforms = platforms.all; + }; +} diff --git a/pkgs/rbdyn/default.nix b/pkgs/rbdyn/default.nix index 1bcf274..6e90d9f 100644 --- a/pkgs/rbdyn/default.nix +++ b/pkgs/rbdyn/default.nix @@ -7,6 +7,7 @@ tinyxml-2, boost, fetchurl, + python3Packages, }: stdenv.mkDerivation rec { @@ -18,22 +19,20 @@ stdenv.mkDerivation rec { sha256 = "sha256-IFqX4z8r2JTwgNnPB35/vZKwgWoPO78ebnUvPdNOnjY="; }; - nativeBuildInputs = [ cmake ]; + nativeBuildInputs = [ + cmake + python3Packages.cython + python3Packages.python + ]; + propagatedBuildInputs = [ spacevecalg yaml-cpp tinyxml-2 boost + python3Packages.spacevecalg ]; # Add other dependencies here - postPatch = '' - # Remove the include from the main CMakeLists.txt - sed -i '/include(cmake\/cython\/cython.cmake)/d' CMakeLists.txt - - # Add the include to the top of the python binding CMakeLists.txt - sed -i '1i include(cmake/cython/cython.cmake)' binding/python/CMakeLists.txt - ''; - doCheck = true; meta = with lib; { diff --git a/pkgs/spacevecalg/default.nix b/pkgs/spacevecalg/default.nix index 5b2c1e4..c8743a0 100644 --- a/pkgs/spacevecalg/default.nix +++ b/pkgs/spacevecalg/default.nix @@ -2,18 +2,18 @@ stdenv, lib, cmake, + pkg-config, jrl-cmakemodules, + doxygen, eigen, boost, fetchFromGitHub, + python3Packages, }: -let - version = "1.2.9"; -in -stdenv.mkDerivation rec { +stdenv.mkDerivation { pname = "spacevecalg"; - inherit version; + version = "1.2.9"; src = fetchFromGitHub { owner = "jrl-umi3218"; @@ -25,17 +25,25 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ cmake jrl-cmakemodules + pkg-config + doxygen + python3Packages.cython + python3Packages.python + python3Packages.distutils + python3Packages.pytest ]; + propagatedBuildInputs = [ eigen boost + python3Packages.numpy + python3Packages.eigen3-to-python ]; - cmakeFlags = [ - "-DBUILD_TESTING=OFF" - "-DPYTHON_BINDING=OFF" - "-DINSTALL_DOCUMENTATION=OFF" - ]; + # cmakeFlags = [ + # "-DBUILD_TESTING=OFF" + # "-DINSTALL_DOCUMENTATION=OFF" + # ]; doCheck = true; diff --git a/py-pkgs/eigen3-to-python.nix b/py-pkgs/eigen3-to-python.nix new file mode 100644 index 0000000..10c3727 --- /dev/null +++ b/py-pkgs/eigen3-to-python.nix @@ -0,0 +1,9 @@ +{ + toPythonModule, + pkgs, +}: +toPythonModule ( + pkgs.eigen3-to-python.override { + inherit (pkgs) python3Packages; + } +) diff --git a/py-pkgs/spacevecalg.nix b/py-pkgs/spacevecalg.nix new file mode 100644 index 0000000..9e6d05c --- /dev/null +++ b/py-pkgs/spacevecalg.nix @@ -0,0 +1,9 @@ +{ + toPythonModule, + pkgs, +}: +toPythonModule ( + pkgs.spacevecalg.override { + inherit (pkgs) python3Packages; + } +) From 55784e035eb637826a2f3f3a176c800748a11fb9 Mon Sep 17 00:00:00 2001 From: Arnaud TANGUY Date: Tue, 2 Jun 2026 14:01:07 +0200 Subject: [PATCH 2/4] python: rbdyn --- pkgs/rbdyn/default.nix | 8 ++++++++ py-pkgs/rbdyn.nix | 9 +++++++++ 2 files changed, 17 insertions(+) create mode 100644 py-pkgs/rbdyn.nix diff --git a/pkgs/rbdyn/default.nix b/pkgs/rbdyn/default.nix index 6e90d9f..610e7a6 100644 --- a/pkgs/rbdyn/default.nix +++ b/pkgs/rbdyn/default.nix @@ -23,6 +23,8 @@ stdenv.mkDerivation rec { cmake python3Packages.cython python3Packages.python + python3Packages.distutils + python3Packages.pytest ]; propagatedBuildInputs = [ @@ -33,6 +35,12 @@ stdenv.mkDerivation rec { python3Packages.spacevecalg ]; # Add other dependencies here + # XXX: Without this fixupPhase fails due to RPATHS references to /build/ + preFixup = '' + patchelf --shrink-rpath --allowed-rpath-prefixes "$NIX_STORE" $out/${python3Packages.python.sitePackages}/rbdyn/rbdyn.so + patchelf --shrink-rpath --allowed-rpath-prefixes "$NIX_STORE" $out/${python3Packages.python.sitePackages}/rbdyn/parsers/parsers.so + ''; + doCheck = true; meta = with lib; { diff --git a/py-pkgs/rbdyn.nix b/py-pkgs/rbdyn.nix new file mode 100644 index 0000000..b24f1b2 --- /dev/null +++ b/py-pkgs/rbdyn.nix @@ -0,0 +1,9 @@ +{ + toPythonModule, + pkgs, +}: +toPythonModule ( + pkgs.rbdyn.override { + inherit (pkgs) python3Packages; + } +) From 5f4aeb1c7d9cc07f812cb35fef46aa0a8e0df6a2 Mon Sep 17 00:00:00 2001 From: Arnaud TANGUY Date: Tue, 2 Jun 2026 14:51:26 +0200 Subject: [PATCH 3/4] python: tasks, sch-core-python --- module.nix | 1 + overlay.nix | 1 + pkgs/sch-core-python/default.nix | 65 ++++++++++++++++++++++++++++++++ pkgs/tasks/default.nix | 22 +++++++---- py-pkgs/sch-core-python.nix | 9 +++++ py-pkgs/tasks.nix | 9 +++++ 6 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 pkgs/sch-core-python/default.nix create mode 100644 py-pkgs/sch-core-python.nix create mode 100644 py-pkgs/tasks.nix diff --git a/module.nix b/module.nix index 288cb64..869a840 100644 --- a/module.nix +++ b/module.nix @@ -73,6 +73,7 @@ in spacevecalg rbdyn sch-core + sch-core-python tasks tasks-qld tvm diff --git a/overlay.nix b/overlay.nix index 187d217..8552c2f 100644 --- a/overlay.nix +++ b/overlay.nix @@ -52,6 +52,7 @@ eigen-qld = prev.callPackage ./pkgs/eigen-qld { }; eigen-quadprog = prev.callPackage ./pkgs/eigen-quadprog { }; sch-core = prev.callPackage ./pkgs/sch-core { }; + sch-core-python = prev.callPackage ./pkgs/sch-core-python { }; #sch-visualization = prev.callPackage ./pkgs/sch-visualization {}; sch-visualization = prev.callPackage ./pkgs/sch-visualization { }; tasks-qld = prev.callPackage ./pkgs/tasks { }; diff --git a/pkgs/sch-core-python/default.nix b/pkgs/sch-core-python/default.nix new file mode 100644 index 0000000..b065822 --- /dev/null +++ b/pkgs/sch-core-python/default.nix @@ -0,0 +1,65 @@ +{ + lib, + stdenv, + cmake, + sch-core, + spacevecalg, + python3Packages, + fetchFromGitHub, +}: + +stdenv.mkDerivation rec { + pname = "sch-core-python"; + version = "1.0.5"; + + src = fetchFromGitHub { + owner = "jrl-umi3218"; + repo = "sch-core-python"; + rev = "9b4a7d8189de30dc49edc7ccb0e1283e85686e62"; + hash = "sha256-Ml0fATe61R7tJ5m20Y7hjDwCa/WwIIG3f+qwV1zSz8k="; + }; + + nativeBuildInputs = [ + cmake + python3Packages.cython + python3Packages.python + python3Packages.distutils + python3Packages.pytest + ]; + propagatedBuildInputs = [ + sch-core + spacevecalg + python3Packages.spacevecalg + ]; + + cmakeFlags = [ + "-DINSTALL_DOCUMENTATION=OFF" + ]; + + # Override the default CMake install step + installPhase = '' + runHook preInstall + + # 1. Define the destination directory inside the Nix store output + # Using python.sitePackages handles the "lib/python3.13/site-packages" string automatically + local targetDir="$out/${python3Packages.python.sitePackages}/sch" + mkdir -p "$targetDir" + + ls -lR + + # 2. Copy your built files from the build tree to the target store path + # (Adjust 'build/python/Release/eigen/' path if your build folder structure differs slightly) + cp -r python/Release/sch/* "$targetDir" + + runHook postInstall + ''; + + doCheck = false; + + meta = with lib; { + description = "sch-core: python bindings for sch-core - effective proximity queries"; + homepage = "https://github.com/jrl-umi3218/sch-core-python"; + license = licenses.bsd2; + platforms = platforms.all; + }; +} diff --git a/pkgs/tasks/default.nix b/pkgs/tasks/default.nix index c66e20b..aca8029 100644 --- a/pkgs/tasks/default.nix +++ b/pkgs/tasks/default.nix @@ -5,6 +5,7 @@ rbdyn, sch-core, eigen-qld, + python3Packages, with-lssol ? false, eigen-lssol ? null, }: @@ -18,25 +19,30 @@ stdenv.mkDerivation rec { sha256 = "0if144c0jjpxk97fn2qszybdlx8b66qsa1kdkvwzfipvf8fh364q"; }; - nativeBuildInputs = [ cmake ]; + nativeBuildInputs = [ + cmake + python3Packages.distutils + python3Packages.pytest + python3Packages.cython + python3Packages.python + ]; propagatedBuildInputs = [ rbdyn sch-core eigen-qld + python3Packages.rbdyn + python3Packages.sch-core-python ] ++ lib.optional (with-lssol && eigen-lssol != null) eigen-lssol; cmakeFlags = [ - "-DPYTHON_BINDING=OFF" "-DINSTALL_DOCUMENTATION=OFF" ]; - postPatch = '' - # Remove the include from the main CMakeLists.txt - sed -i '/include(cmake\/cython\/cython.cmake)/d' CMakeLists.txt - - # Add the include to the top of the python binding CMakeLists.txt - sed -i '1i include(cmake/cython/cython.cmake)' binding/python/CMakeLists.txt + # XXX: Without this fixupPhase fails due to RPATHS references to /build/ + preFixup = '' + patchelf --shrink-rpath --allowed-rpath-prefixes "$NIX_STORE" $out/${python3Packages.python.sitePackages}/tasks/tasks.so + patchelf --shrink-rpath --allowed-rpath-prefixes "$NIX_STORE" $out/${python3Packages.python.sitePackages}/tasks/qp/qp.so ''; doCheck = true; diff --git a/py-pkgs/sch-core-python.nix b/py-pkgs/sch-core-python.nix new file mode 100644 index 0000000..5e0029e --- /dev/null +++ b/py-pkgs/sch-core-python.nix @@ -0,0 +1,9 @@ +{ + toPythonModule, + pkgs, +}: +toPythonModule ( + pkgs.sch-core-python.override { + inherit (pkgs) python3Packages; + } +) diff --git a/py-pkgs/tasks.nix b/py-pkgs/tasks.nix new file mode 100644 index 0000000..f05fc2a --- /dev/null +++ b/py-pkgs/tasks.nix @@ -0,0 +1,9 @@ +{ + toPythonModule, + pkgs, +}: +toPythonModule ( + pkgs.tasks.override { + inherit (pkgs) python3Packages; + } +) From ca45dcc185d27264d6dbb3d38bdb96a27bdeead8 Mon Sep 17 00:00:00 2001 From: Arnaud TANGUY Date: Tue, 2 Jun 2026 15:40:31 +0200 Subject: [PATCH 4/4] python: mc-rtc --- pkgs/mc-rtc/mc-rtc-common.nix | 7 ++++--- pkgs/mc-rtc/mc-rtc.nix | 24 +++++++++++++++--------- py-pkgs/mc-rtc.nix | 9 +++++++++ 3 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 py-pkgs/mc-rtc.nix diff --git a/pkgs/mc-rtc/mc-rtc-common.nix b/pkgs/mc-rtc/mc-rtc-common.nix index e6985af..ef34b47 100644 --- a/pkgs/mc-rtc/mc-rtc-common.nix +++ b/pkgs/mc-rtc/mc-rtc-common.nix @@ -4,11 +4,12 @@ let version = "2.14.1"; + # TODO: PR 538 src = fetchFromGitHub { - owner = "jrl-umi3218"; + owner = "Kooolkimooov"; repo = "mc_rtc"; - rev = "d1bb28f9bfab85a04ce1ff103289676cfa5bf4fc"; - hash = "sha256-a8Wh5Xhvs+vM7k0uEJzSDCSUOK58AJSRSJx3XyboHO0="; + rev = "2846f365824531f162635323d0c32796842e02a8"; + hash = "sha256-zTxxZOZCwlMGrRGG8B9kRLJcCvXLvYSigej8yDpihwg="; }; in { diff --git a/pkgs/mc-rtc/mc-rtc.nix b/pkgs/mc-rtc/mc-rtc.nix index b5c5fb8..544ab49 100644 --- a/pkgs/mc-rtc/mc-rtc.nix +++ b/pkgs/mc-rtc/mc-rtc.nix @@ -15,6 +15,7 @@ libtool, geos, spdlog, + fmt, ndcurves, mc-rtc-data, state-observation, @@ -23,9 +24,8 @@ rapidjson, boost, mesh-sampling, - python313Packages, + python3Packages, qt5, - eigen-fmt, doxygen, bundler, # Ruby for bundle dependencies with-ros ? false, @@ -61,6 +61,10 @@ in pkg-config jrl-cmakemodules qt5.wrapQtAppsHook + python3Packages.distutils + python3Packages.pytest + python3Packages.cython + python3Packages.python ] ++ [ # for documentation @@ -83,13 +87,16 @@ in rapidjson boost mesh-sampling - eigen-fmt - ] - ++ [ - python313Packages.gitpython - python313Packages.pyqt5 - python313Packages.matplotlib + fmt + python3Packages.tasks ] + ++ + # for python utils (mc_rtc_new_fsm_controller, mc_log_ui, etc) + [ + python3Packages.gitpython + python3Packages.pyqt5 + python3Packages.matplotlib + ] ++ lib.optional (with-ros && rclcpp != null) rclcpp ++ lib.optional (with-ros && nav-msgs != null) nav-msgs ++ lib.optional (with-ros && sensor-msgs != null) sensor-msgs @@ -106,7 +113,6 @@ in cmakeFlags = [ "-DBUILD_MC_RTC_PYTHON_UTILS=ON" "-DBUILD_TESTING=OFF" - "-DPYTHON_BINDING=OFF" "-DINSTALL_DOCUMENTATION=ON" ]; diff --git a/py-pkgs/mc-rtc.nix b/py-pkgs/mc-rtc.nix new file mode 100644 index 0000000..3efdc68 --- /dev/null +++ b/py-pkgs/mc-rtc.nix @@ -0,0 +1,9 @@ +{ + toPythonModule, + pkgs, +}: +toPythonModule ( + pkgs.mc-rtc.override { + inherit (pkgs) python3Packages; + } +)