How to set ROS_MASTER_URI with snapcraft

Absolutely, @thymythos. There are a few different ways that can be achieved, but the easiest is probably to make your app a simple wrapper that handles that configuration and properly sets that environment variable. I worked up a quick example for you that does nothing more than snap rostopic.

The idea is this:

As a quick demo, I didn’t have roscore running locally, but I had it running on 10.203.138.130:

$ snapcraft
<snip>       
Snapped ros-configurable-master-uri_0.1_amd64.snap

$ sudo snap install ros-configurable-master-uri_0.1_amd64.snap --dangerous
ros-configurable-master-uri 0.1 installed

$ sudo snap get ros-configurable-master-uri ros-master-uri
http://localhost:11311

$ ros-configurable-master-uri.rostopic list
ERROR: Unable to communicate with master!

$ sudo snap set ros-configurable-master-uri ros-master-uri=http://10.203.138.130:11311

$ sudo snap get ros-configurable-master-uri ros-master-uri
http://10.203.138.130:11311

$ ros-configurable-master-uri.rostopic list
/rosout
/rosout_agg

Note that the configure hook can help ensure an invalid config isn’t accepted (although my regex is pretty bare-bones as you can tell):

$ sudo snap set ros-configurable-master-uri ros-master-uri=foo
error: cannot perform the following tasks:
- Run configure hook of "ros-configurable-master-uri" snap (run hook "configure": 'foo' is not a valid ROS master URI)

$ sudo snap get ros-configurable-master-uri ros-master-uri
http://10.203.138.130:11311