Hey all, I’m trying to get the RISC-V GNU Toolchain set up for use in a nix develop
shell. Specifically, I need access to the riscv-unknown-elf-*
tools.
I known that Nix supports tooling for cross-compilation like this:
outputs = { self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
riscv-toolchain = import nixpkgs {
localSystem = "${system}";
crossSystem = {
config = "riscv64-unknown-linux-gnu";
};
};
in
{
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
riscv-toolchain.buildPackages.gcc
];
};
}
);
Which gives me access to the riscv-unkown-linux-gnu-*
tools. However, when I set riscv-toolchain.crossSystem.config
to risc64-unknown-elf
, I get the error Unknown kernel: unknown
, which isn’t very helpful to say the least.
On a non-NixOS system I’d just build the repo myself from source, so I tried creating a typical mkDerivation
, like so:
outputs = { self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
riscv-toolchain = pkgs.stdenv.mkDerivation {
name = "riscv-toolchain";
dontPatchELF = true;
fetchSubmodules = true;
src = pkgs.fetchFromGitHub {
owner = "riscv";
repo = "riscv-gnu-toolchain";
rev = "b39e36160aa0649ba0dfb9aa314d375900d610fb";
sha256 = "0qqp9w6595saw9gzq73n6plhdc1r1mrswjagxmqkzd1fxg7hwjzn";
};
configureFlags = "--with-arch=rv64g";
buildInputs = with pkgs; [ gmp libmpc mpfr gawk bison flex texinfo gperf curl git flock ];
};
in
{
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
riscv-toolchain
];
};
}
);
But that just results in tis rather hard to comprehend error:
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/q5fw16am9jjw53w9a8c1lzj23aymf5fr-source
source root is source
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
configure flags: --prefix=/nix/store/kn63j4j1s0kpgxspyf37rn38sysl7hky-riscv-toolchain --with-arch=rv64g
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for grep that handles long lines and -e... /nix/store/gpjwx73lj7bynf2z0gamlwy47dzxdbml-gnugrep-3.6/bin/grep
checking for fgrep... /nix/store/gpjwx73lj7bynf2z0gamlwy47dzxdbml-gnugrep-3.6/bin/grep -F
checking for grep that handles long lines and -e... (cached) /nix/store/gpjwx73lj7bynf2z0gamlwy47dzxdbml-gnugrep-3.6/bin/grep
checking for bash... /nix/store/wv35g5lff84rray15zlzarcqi9fxzz84-bash-4.4-p23/bin/bash
checking for __gmpz_init in -lgmp... yes
checking for mpfr_init in -lmpfr... yes
checking for mpc_init2 in -lmpc... yes
checking for curl... /nix/store/3npnq65by4nxvw103svzi73b5qd78igw-curl-7.76.1-bin/bin/curl
checking for wget... no
checking for ftp... no
configure: creating ./config.status
config.status: creating Makefile
config.status: creating scripts/wrapper/awk/awk
config.status: creating scripts/wrapper/sed/sed
@nix { "action": "setPhase", "phase": "buildPhase" }
building
cd /build/source && \
flock `git rev-parse --git-dir`/config git submodule init /build/source/riscv-gcc/ && \
flock `git rev-parse --git-dir`/config git submodule update /build/source/riscv-gcc/
cd /build/source && \
flock `git rev-parse --git-dir`/config git submodule init /build/source/riscv-gcc/ && \
flock `git rev-parse --git-dir`/config git submodule update /build/source/riscv-gcc/
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
flock: cannot open lock file /config: Permission denied
flock: invalid input: Permission denied
make: *** [Makefile:247: /build/source/riscv-gcc/.git] Error 66
flock: cannot open lock file /config: Permission denied
flock: invalid input: Permission denied
make: *** [Makefile:247: /build/source/riscv-gcc/.git] Error 66
Does anyway have any experience with this? Am I going about this the wrong way?
Thanks!