Build issues at link time using rustup for cross-compilation

Hi first post!
I played arround with hubris today, and I’m having a bit of trouble compiling the systems.

I used this shell.nix

{ pkgs ? import <nixpkgs> {} }:
  pkgs.mkShell rec {
    buildInputs = with pkgs; [
    RUSTC_VERSION = pkgs.lib.readFile ./rust-toolchain.toml;
    LIBCLANG_PATH = pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ];
    shellHook = ''
      export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin
      export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/
    # Add precompiled library to rustc search path
    RUSTFLAGS = ( (a: ''-L ${a}/lib'') [
      # add libraries here (e.g. pkgs.libvmi)
    # Add glibc, clang, glib and other headers to bindgen search path
    # Includes with normal include path
    ( (a: ''-I"${a}/include"'') [
      # add dev libraries here (e.g. 
    # Includes with special directory paths
    ++ [

And issued the following command to build the stm32f4-discovery demo.

cargo xtask dist app/demo-stm32f4-discovery/app.toml

The build goes well at first, but at linking time the seems to be a problem

    Finished release [optimized + debuginfo] target(s) in 0.27s
target/thumbv7em-none-eabihf/release/task-idle -> target/demo-stm32f4-discovery/dist/idle.elf
Error: failed to run linker ("/home/nic/.rustup/toolchains/nightly-2022-11-01-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld/ld.lld" "jefe.elf" "-o" "jefe.tmp" "-Tlink.x" "--gc-sections" "-m" "armelf" "-z" "common-page-size=0x20" "-z" "max-page-size=0x20")

Caused by:
    No such file or directory (os error 2)

I tried the same build on an Arch box and it went fine, I’m curious what the cause of this problem is.

I found a part of the solution in this post.

nix --extra-experimental-features flakes run nixpkgs#patchelf -- --set-interpreter "$(nix --extra-experimental-features flakes eval --raw)" /home/nic/.rustup/toolchains/nightly-2022-11-01-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld/ld.lld

Using this snippet I was able to link the binary. I’m still unsure how to edit my shell.nix to have this done automatically…