To enter a nix-shell
with the ROS Kinetic Comm variant available, run,
$ nix-shell ros.nix
(Note that building everything takes some time!). This is actually a slight extension of the stock comm
variant so that the turtlesim tutorial can run.
If you want to regenerate the kinetic_perception.nix
file that defines all the ROS packages that make up the distribution, you will use the ros2nix
program:
$ stack exec ros2nix -- $(nix-build --no-out-link ./ros-distro.nix -A kinetic.perception-src)/kinetic_perception.rosinstall -o kinetic_perception.nix
If you want to use a different ROS distribution or variant, change the
-A kinetic.perception-src
part of the ros2nix
incantation. If you
want to use a minimal set of core packages, consider using
kinetic.ros_comm-src
for the comm
ROS configuration.
-
The
ros-distro.nix
file uses ROS tooling to obtain a.rosinstall
file for the desired metapackage/variant (in the above examples, we referred to theperception
andcomm
variants of the ROSkinetic
distribution). -
The
ros2nix
program (called withstack exec
above) generates derivations for all the packages that make up the ROS distribution. In the example, we output those definitions to the filekinetic_perception.nix
. -
The
ros.nix
file identifies that we want to loadkinetic_comm.nix
and extend it with, for the sake of a satisfying example,turtlesim.nix
. The full environment is constructed by mixing fixed ROS environment components specified inros-build-env.nix
with the specific package set identified by, for example,kinetic_comm.nix
. -
Entering a
nix-shell ros.nix
sets up theROS_PACKAGE_PATH
,ROS_MASTER_URI
, and thePYTHONPATH
such that each package can be found.
To see if things are working, try starting a master node!
In one shell,
$ nix-shell ros.nix
$ roscore
In another,
$ nix-shell ros.nix
$ rosrun turtlesim turtlesim_node
and in yet another,
$ nix-shell ros.nix
$ rosrun turtlesim turtle_teleop_key
The ros2nix
program uses a cache mapping package names to Nix hashes of their source. The way that I generate the cache is by loading src/Main.hs
in a GHCi REPL, and calling generateCache "/nix/store/..../kinetic_perception.rosinstall" "perception_hash_cache.txt"
. The ros2nix
program looks for that file, and, if it exists, uses it as a cache. If the file does not exist, it will download each ROS package. The use of this cache file was primarily intended for the development of ros2nix
when it was being repeatedly run against the same .rosinstall
files. It might not be necessary as the program stabilizes and is used less frequently.
The infrastructure for using a pinned version of nixpkgs
is included but not currently in use. I am awaiting the merging of a couple Pull Requests critical to having the turtlesim
example work on macOS.