Embassy, probe-rs on NixOS

I’m trying to take Embassy for a spin on a NixOS machine. Embassy requires probe-rs, which is available in nixpkgs.

The getting started instructions for Embassy suggest that one install

  • rustup (For the purposes of installing the Rust toolchain. I don’t have rustup as such, but I am doing this in a flake that supplies the Rust toolchain via the oxalica Rust overlay).
  • probe-rs (My flake gets this from nixpkgs.)

and then

  • clone the Embassy repo
  • cd into examples/<my-board>
  • cargo build --bin blinky --release

This fails, spewing many screenfuls of Rust compiler errors, starting with

error[E0463]: can't find crate for `core`

The Embassy Getting Started docs have an “It didn’t work” section, which includes

If you’re getting an extremely long error message containing something like the following:

error[E0463]: can't find crate for `std`

Make sure that you didn’t accidentally run cargo add probe-rs (which adds it as a dependency) instead of correctly installing probe-rs.

Given that core and std are strongly related, the error message I observe and the error message that the docs anticipate may be equivalent.

The “correctly installing probe-rs” instructions amount to

  • curl --proto '=https' --tlsv1.2 -LsSf https://github.com/probe-rs/probe-rs/releases/latest/download/probe-rs-installer.sh | sh
  • cargo install probe-rs --features cli

If I remove probe-rs from the flake and follow these installation instructions, unsurprisingly, they produce an executable which fails to run on NixOS. The flake-provided probe-rs at least managed to give me a sensible response to probe-rs -h.

Have you any suggestions on how to get around this hurdle?

Hi,

I have a toy project which use embassy both for esp32 & stm32. Here is my shell.nix which was working on NixOS last I check: https://github.com/nim65s/RobotS/blob/3a8f4b3c09b7f44382269c19a657d434024b0ef1/shell.nix

Just wanted to report that replacing my flake’s devShell with yours, and commenting out the setting of RUSTC_VERSION gets me around the compilation errors. Then there are run-time problems, but further investigation will have to wait until I have some more spare time.

Edit: I get equivalent behaviour by adding pkgs.rustup to my original devShell. So it seems that rustup is somehow necessary for the standard crates to be found. I don’t recall this being necessary for my other Rust flakes.

No, it looks like it’s needed to add a missing target. In my original report, I overlooked this part of the error message:

  = note: the `thumbv7em-none-eabihf` target may not be installed
  = help: consider downloading the target with `rustup target add thumbv7em-none-eabihf`

This target can be added in the oxalica overlay like this:

rust-bin.stable.latest.default.override {
  targets = [ "thumbv7em-none-eabihf" ];
}

which is a much more declarative and in-the-sprit-of-Nix approach than letting rustup add it dynamically. Also, adding pkgs.rustup seems to break cargo in some uses.