I want to use artiq_flash through a remote machine using artiq_flash -V variant --host remote_machine_hostname, but I get the error bash: openocd: command not found. The local and the remote machine both run Ubuntu 20.04.

I installed openocd-mlabs using nix-env to make sure the command is available without a nix shell, but I realized that paramiko spawns a non-interactive SSH session which does not load ~/.profile. Hence, the nix environment is not added to PATH and the openocd command is not available. So it seems this structure does not allow remote flashing.

Is this a bug, or do other people solve this differently?

I count it as a bug. I haven't tried using it in combination with nix-env, only with system-wide openocd on NixOS.

ok. I will see if I can come up with a fix next week or so.

a month later

Ok so I tried various settings for paramiko, but it seems that it is not able to open a "login" shell, which is required to load the ~/.profile which in turn loads the Nix environment. We run on Ubuntu 20.04, but I assume it is not the only distro that behaves like this.

An alternative approach is to invoke bash through paramiko and configure it to open a login shell. See the example below where $SHELL is /bin/bash (Ubuntu default).

euriqa@red-chamber:/tmp/artiq$ ssh red-chamber-rpi 'openocd --version'
bash: openocd: command not found
euriqa@red-chamber:/tmp/artiq$ ssh red-chamber-rpi '$SHELL -l -c "openocd --version"'
Open On-Chip Debugger 0.10.0-snapshot (2021-05-17-15:29)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html

A few questions @sb10q

  1. This can be inserted into the openocd command we send through paramiko. Do you think this is a reasonable solution?
  2. Should this become an option for artiq_flash, for example --bash? And if so, should we use $SHELL in the command or explicitly invoke /bin/bash? (The -l -c options might not work on other shell commands).

If we decide what to do, I can make a PR.

Changing every paramiko command into bash --login -c "exec openocd..." seems fine to me. No need for the command-line flag.

(Assuming that bash is installed does not sound like more reckless than assuming $SHELL understands the command-line arguments correctly, and would produce a clearer error message when the assumption fails)