Makefile seems to write the read only file system

I’m trying to build the riscv-toolchain for practice.( I know there is a cross compile tool in nix but just for practice purpose ). So I wrote a simple nix expression below.

let riscv_toolchain = with import <nixpkgs>{};
stdenv.mkDerivation {
    name = "riscv_toolchain";
    src = fetchFromGitHub{
        owner = "riscv";
        repo = "riscv-gnu-toolchain";
        rev = "b39e36160aa0649ba0dfb9aa314d375900d610fb";
        sha256 = "sha256-MI3DesAnMDVJ9VQ6QmoLOt4dnGMdjS32sUQcVBCJoYU=";
    buildInputs = [ gmp libmpc mpfr gawk bison flex texinfo gperf curl git flock ];
with import <nixpkgs> {};
mkShell {
    packages = [

However the building process failed and here is the output.

error: builder for '/nix/store/jqxn1sfd380kgi45fwjr2npxljqj2vq6-riscv_toolchain.drv' failed with exit code 2;
       last 10 log lines:
       > config.status: creating scripts/wrapper/sed/sed
       > building
       > build flags: SHELL=/nix/store/xx5s0rkx3aav3f850ig4afadg6ms7lq9-bash-5.2-p15/bin/bash
       > cd /private/tmp/nix-build-riscv_toolchain.drv-0/source && \
       > flock `git rev-parse --git-dir`/config git submodule init /private/tmp/nix-build-riscv_toolchain.drv-0/source/riscv-gcc/ && \
       > flock `git rev-parse --git-dir`/config git submodule update /private/tmp/nix-build-riscv_toolchain.drv-0/source/riscv-gcc/
       > fatal error: Not a git repository (or any of the parent directories): .git
       > flock: cannot open lock file /config: Read-only file system
       > flock: could not create file: Read-only file system
       > make: *** [Makefile:247: /private/tmp/nix-build-riscv_toolchain.drv-0/source/riscv-gcc/.git] Error 73
       For full logs, run 'nix-store -l /nix/store/jqxn1sfd380kgi45fwjr2npxljqj2vq6-riscv_toolchain.drv'.

I guess maybe the makefile want to config the toolchain file which located in the store directory. But I can’t solve it. Anyone can do me a favor? Thanks very much

The error is fairly obvious if you take a look at the error message:

It tries to write to the config sub-directory of the directory which git rev-parse --git-dir outputs. git rev-parse --git-dir fails however (we strip the .git directory), so it returns an empty string; "" + "/config" = "/config".

What you’d do in such a case is check whether you’re able to declare the directory it’s trying to find at runtime using git, ahead of time via a configure option or a patch. Alternatively, you could create a fake mocked “git” which outputs your desired directory.

In this case, it seems to be doing that in order to fetch submodules. That isn’t going to work either way because you don’t have internet access inside the nix sandbox.
The way to fix that would be to fetchSubmodules = true; in fetchFromGitHub (remember to update the hash) and then tell the build system to not try do that on its own which it shouldn’t try to do in the first place. This smells of a bad build system that you aren’t going to have fun with tbh. Expect to patch it a lot.

1 Like