Choose the hardware target with MIX_TARGET
Set MIX_TARGET to a Nerves target such as rpi4 before running mix commands, so dependencies and the firmware are built for the board and not the host.
A Nerves project builds for your laptop by default, with MIX_TARGET=host, which is why mix test works without a board. To build for hardware, name the target in the environment, and do it for every Mix command in the session, since each target has its own dependencies and build directory.
export MIX_TARGET=rpi4
mix deps.get
mix firmwareNerves environment
MIX_TARGET: rpi4
MIX_ENV: devThe banner is printed at the start of each Nerves-aware command. The Nerves system for the target, such as nerves_system_rpi4, is fetched on the first deps.get, and its toolchain with it. A common mistake is exporting the variable in one terminal and running mix deps.get in another, which then resolves host dependencies and fails with confusing errors at mix firmware. Targets must be listed in mix.exs, where a project made by mix nerves.new keeps them in the @all_targets attribute, and a target missing there is silently built as if it were the host. Valid names are those of the Nerves systems, including rpi0, rpi3, rpi4 and bbb. See the Nerves targets documentation.