GitHub - akssri/nix-robotml: nix env. for robot+ml development.

2 min read Original article ↗

robot-nix : dev/deploy env. for ros2 + ml

Robotics + ML development is not simple. Frameworks like ROS require Ubuntu or Docker. ML requires a CUDA setup along with Python dependencies, necessitating venv or Docker. Combining these two is even more troublesome.

Nix flake shells offer a better solution.

Not only do you get a shell/environment on your local machine like venv without any of the development barriers put up by containerization, but these shells also easily containerize from the ground up for quick and reliable deployment (without depending on any base image!).

The repo below is a cleaned-up version of the recipes I use.

requirements

  • Nix w/ nix-command flakes enabled.
  • NixGL (optional, for CUDA on non-NixOS machines)
  • nix-direnv (optional, for caching nix-shell)
  • Docker/Podman w/ Nvidia CTK (optional)

ros + ml env. with nix-flakes

> git clone https://github.com/akssri/nix-robotml.git
> cd nix-robotml
> nix develop # use .#ros or .#ml suffix for ros/ml-only env.
...
> ros2 topic list
> python -c 'import jax.numpy as jnp' # nixGL <command> (for CUDA, on non-NixOS)

Nix is declarative and lacks a package manager, ergo rosdep cannot work like it does on Ubuntu. Therefore, we need to use this workaround,

[KN]: Nix ಪ್ರತಿಜ್ಞಾತ್ಮಕವಾಗಿರುವುದರಿಂದ (declarative) ಮತ್ತು ಪ್ಯಾಕೇಜ್-ಮ್ಯಾನೇಜರ್ ಇಲ್ಲದಿರುವದರಿಂದ, rosdep Ubuntu-ವಿನಂತೆ ಕೆಲಸ ಮಾಡಲಾರುದು. ಅದಕ್ಕಾಗಿ ನಾವು ಈ ಉಪಾಯವನ್ನು ಬಳಸಬೇಕು,

[HI]: Nix प्रतिज्ञात्मक होने की कारण (declarative) और इसमें पैकेज-मैनेजर न होने की कारण, rosdep Ubuntu की तरह काम नहीं कर सकता। इसलिए हमें यह उपाय अपनाना होगा,

> cd ros_ws/
> rosdep keys --from-paths src --ignore-src | sed "s|_|-|g"
backward-ros
control-msgs
ament-cmake-clang-format
rsl
moveit-kinematics
joint-state-broadcaster
controller-interface
joint-state-publisher
robot-state-publisher
...
> # PASTE output into ros-shell.nix; rebuild env.
> colcon build <args>

nix env. -> container

> nix build .#docker.x86_64-linux
> podman load < result
> podman run -it --rm --device nvidia.com/gpu=all localhost/nix-ros-ml bash

acknowledgements