lopsided98 / nix-ros-overlay

ROS overlay for the Nix package manager
Apache License 2.0
173 stars 69 forks source link

[support] getting rqt working in home-mananger #368

Closed traverseda closed 4 months ago

traverseda commented 4 months ago

Sorry about posting this in an issue, it's the last thing keeping me from moving to nix full-time professionally. I'm pretty new to nix, so apologies if this is something basic I'm just missing.

I'm having a hard time getting rqt to run from home manager, here's a simplified example of my home-mananger config

let
  ros = builtins.getFlake "github:lopsided98/nix-ros-overlay";
in
{
  home.packages = [
    ros.legacyPackages.x86_64-linux.noetic.rostopic
    ros.legacyPackages.x86_64-linux.noetic.rqt-gui
    ros.legacyPackages.x86_64-linux.noetic.rqt-gui-py
    ros.legacyPackages.x86_64-linux.noetic.rqt
  ];
}

And when I try to run rqt I get

Traceback (most recent call last):
  File "/nix/store/xxxbnf8kwc3bq4cwvab5d3pnm5q52jn5-ros-noetic-rqt-gui-0.5.3-r1/bin/..rqt-wrapped-wrapped", line 9, in <module>
    p = r.get_path('rqt_gui')
        ^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/1vq2i3aykn5npiclifj6qxyyvkbg1ari-python3.11-rospkg-1.4.0/lib/python3.11/site-packages/rospkg/rospack.py", line 207, in get_path
    raise ResourceNotFound(name, ros_paths=self._ros_paths)
rospkg.common.ResourceNotFound: rqt_gui

Any thoughts?

wentasah commented 4 months ago

Try adding your ROS packages to a buildEnv. This ensures that all binaries are properly wrapped and all needed environment variables are set. The following works for me:

{ pkgs, ... }:
let
  ros = builtins.getFlake "github:lopsided98/nix-ros-overlay";
in
{
  home.packages = [
    (with ros.legacyPackages.x86_64-linux.noetic; pkgs.lowPrio (buildEnv {
      paths = [
        rostopic
        rqt-gui
        rqt-gui-py
        rqt
      ];
    }))
  ];
}

Note that I had to add pkgs.lowPrio to avoid collisions with some other packages in my home-manager environment. If you don't have collisions, you can remove it.

A question is whether it is a good idea to have rqt in your global environment. Fox example, if you need to switch between ROS and ROS 2 projects, having a ROS version installed globally can cause problems in ROS 2 projects. Personally, I prefer having a per-project development environment and using it via nix develop/nix-shell or direnv.

traverseda commented 4 months ago

Yep that works. Thanks a lot