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; [
      clang
      llvmPackages_9.bintools
      rustup
    ];
    RUSTC_VERSION = pkgs.lib.readFile ./rust-toolchain.toml;
    # https://github.com/rust-lang/rust-bindgen#environment-variables
    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 = (builtins.map (a: ''-L ${a}/lib'') [
      # add libraries here (e.g. pkgs.libvmi)
    ]);
    # Add glibc, clang, glib and other headers to bindgen search path
    BINDGEN_EXTRA_CLANG_ARGS = 
    # Includes with normal include path
    (builtins.map (a: ''-I"${a}/include"'') [
      # add dev libraries here (e.g. pkgs.libvmi.dev)
      pkgs.glibc.dev 
    ])
    # Includes with special directory paths
    ++ [
      ''-I"${pkgs.llvmPackages_latest.libclang.lib}/lib/clang/${pkgs.llvmPackages_latest.libclang.version}/include"''
      ''-I"${pkgs.glib.dev}/include/glib-2.0"''
      ''-I${pkgs.glib.out}/lib/glib-2.0/include/''
    ];
}

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 nixpkgs#stdenv.cc.bintools.dynamicLinker --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…