lopsided98 / nix-ros-overlay

ROS overlay for the Nix package manager
Apache License 2.0
206 stars 83 forks source link

How to get rviz? #85

Open werner291 opened 3 years ago

werner291 commented 3 years ago

Hi, sorry for opening so many issues, I think there's something basic I'm not quite getting.

I have added rosPackages.noetic.rviz to the buildInputs of the shell, and nix-shell starts without errors, but then I get rviz: command not found

I'm running into a lot of issues like this... Where the package is definitely there in my /nix/store, but I'm getting not found errors. Is there a command I'm missing that sets up paths?

lopsided98 commented 3 years ago

I can't reproduce this. The following shell works correctly for me:

with import <nix-ros-overlay> {};

mkShell {
  buildInputs = [
      rosPackages.noetic.rviz
  ];
}

For packages with binaries in bin, there is nothing ROS specific going on; the package should just get added to PATH. Some ROS packages don't install binaries to bin and need to be started with rosrun, but this is not the case for rviz.

werner291 commented 3 years ago

Oh... it's the shellHook in my shell.nix file.

I was trying to implement this: https://github.com/lopsided98/nix-ros-overlay/issues/82#issuecomment-781730061 which does give me the Gazebo plugins, but in turn apparently breaks access to rviz.

Commenting the shellHook out gets rviz back... But I still want those plugins. I don't recall if it's possible to concatenate the shellHooks?

let
    moz_overlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz);
    ros_tar = (builtins.fetchTarball {
        name = "nix-ros-overlay";
        #url = "https://github.com/lopsided98/nix-ros-overlay/archive/99f3f46f30549d6aee851b4ef0c341fbc36c1759.tar.gz";
        url = "https://github.com/lopsided98/nix-ros-overlay/archive/cff345f1dc1a3ada3be82e8456ce2ab73be03198.tar.gz";
    });
    ros_overlay = import (ros_tar + "/overlay.nix" );
    nixpkgs = import ros_tar { overlays = [ moz_overlay ]; };
    rust = (nixpkgs.rustChannelOf { channel = "stable"; }).rust.override {
        extensions = [ "rust-src" "rust-analysis" "rls-preview" ];
    };
in
    { pkgs ? nixpkgs }:
pkgs.mkShell {
  buildInputs = with pkgs; with rosPackages.noetic; [
    gazebo
    rust
    gazebo-plugins
    gazebo-ros
    gazebo-ros-pkgs
    gazebo-ros-control
    robot-state-publisher
    hector-slam
    roslaunch
    rostopic
    rosbash
    xacro
    urdf-tutorial
    catkin
    cmake
    gtk3
    libGL
    ros-tutorials
    geometry-tutorials
    rqt-tf-tree
    rviz
    ros-environment
  ];

  LD_LIBRARY_PATH = with pkgs.xlibs; "${pkgs.libGL}/lib";

  # Commenting this out brings rviz back.
  shellHook = "source '${pkgs.rosPackages.noetic.gazebo}/share/gazebo-11/setup.sh'
               export GAZEBO_PLUGIN_PATH=\${GAZEBO_PLUGIN_PATH}:${nixpkgs.rosPackages.noetic.gazebo-ros-control.outPath}/lib
               export ROS_PACKAGE_PATH=\${ROS_PACKAGE_PATH}:${nixpkgs.rosPackages.noetic.urdf-tutorial.outPath}
               export ROS_PACKAGE_PATH=\${ROS_PACKAGE_PATH}:${nixpkgs.rosPackages.noetic.rviz}
               export ROS_PACKAGE_PATH=\${ROS_PACKAGE_PATH}:${nixpkgs.rosPackages.noetic.xacro.outPath}
               source devel/setup.bash";
}
lopsided98 commented 3 years ago

The problem is source devel/setup.bash. That file contains the environment variable values that were used when you first created your catkin workspace, and it overrides the environment variables from nix-shell. The documentation for devel/local_setup.bash makes it sound like it should prevent this problem, but I've found that it doesn't work right either. The only solution I have found so far is to delete the devel and build folders every time I change the packages in the shell.

werner291 commented 3 years ago

Oh, that works, indeed!

One thing you could do, perhaps, is take a parameter to the catkin workspace directory, then run catkin_make (or whatever part of it generates the environment variables) and source the setup script when building the shell environment.

Since catkin is based on cmake, IIRC it should be possible to perform an out-of-source build, so you don't have to modifiy the workspace.