Access to RISCV GNU Toolchain with extra packages built for local system

Hello, I’m trying to do something similar to what was already asked in another post: Getting access to the RISCV GNU Toolchain (riscv64-unknown-elf). The solution would be fine if the only thing I wanted in my environment was the tool, but there are other packages I want to run on my local system.

Right now, I have a shell.nix that looks something like this:

{ pkgs ? import <nixpkgs> {} }:
let
  python-with-my-packages = pkgs.python3.withPackages (p: with p; [
    pyyaml
  ]);

in
pkgs.mkShell {

  buildInputs = [ 
    python-with-my-packages 

    pkgs.gtkwave 
    pkgs.verilog
  ];
}

I was hoping there would be a way to drop in something like pkgs.pkgsCross.riscv32-embedded into the buildInputs, but of course that doesn’t work. Other methods I’ve tried involve setting up the cross-compilation system with crossSystem but that just makes the system try to build all those other packages for a RISC-V target.

I understand there’s the “Nixonic” way of doing it… which would be writing a proper derivation for whatever I’m trying to cross-compile, but I need to be able to build this with Make on any other system if needed. All I need is for the riscv32-none-elf tools to be available along with the above packages.

By the way, I have also tried creating the derivation for riscv-gnu-tools based on picorv32/shell.nix, but I get the same error as the user from the post mentioned above.

Thanks.

1 Like

You can use buildPackages for this a package set where the host platform is whatever is running the build/shell and the target platform (in this case) riscv64. This means that everything will be executable on your system and if packages are compilers, they’ll produce code for riscv64.

{ pkgs ? (import <nixpkgs> { }).pkgsCross.riscv64-embedded }:
let
  python-with-my-packages = pkgs.buildPackages.python3.withPackages (p: with p; [
    pyyaml
  ]);

in
pkgs.mkShell {
  # nativeBuildInputs corresponds to buildPackages; in this case it only
  # makes a small difference, but should be used for clarity/consistency
  nativeBuildInputs = [ 
    python-with-my-packages
    pkgs.buildPackages.gtkwave 
    pkgs.buildPackages.verilog
  ];
}
1 Like