I am attempting to create a devshell for cross-compiling programs to RISC-V, but I need a gcc
built with enableMultilib = true
. I tried to override the gcc
version used by stdenv
when building my shell by doing this in my flake.nix
:
{
inputs = {
nixpkgs.url = "nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{ self
, nixpkgs
, flake-utils
, ...
}:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = (import nixpkgs { inherit system; }).pkgsCross.riscv64-embedded;
gcc_multilib = pkgs.wrapCCWith {
cc = pkgs.gcc.cc.override { enableMultilib = true; };
bintools = pkgs.wrapBintoolsWith {
bintools = pkgs.binutils-unwrapped;
libc = pkgs.newlib;
};
};
in
{
devShells.default = (pkgs.mkShell.override { stdenv = (pkgs.overrideCC pkgs.stdenv gcc_multilib); }) {
# ...
};
});
}
But it seems that with this method, it attempts to build gcc
with its host platform set to riscv64-none-elf
, but as a compiler, it should be set to the actual host system (in my case x86_64-linux
) with the target platform set to riscv64-none-elf
. As such, the derivation fails to build because gcc
does not support riscv64-none-elf
as its host platform.