Building nix: problem packaging

I’m trying to package Nix and it turns out that make all actually tries to write linker output to /usr/local/ (the configured --prefix=), i.e.,

  CXX    src/libmain/shared.o
  CXX    src/libmain/stack.o
  LD     src/libmain/
  CXX    src/libcmd/command.o
  CXX    src/libcmd/installables.o
  CXX    src/libcmd/legacy.o
  CXX    src/libcmd/markdown.o
  LD     src/libcmd/
  LD     src/nix/nix
  GEN    scripts/nix-http-export.cgi
  GEN    scripts/
  GEN    scripts/nix-reduce-build
  GEN    doc/manual/nix-env.1
  GEN    doc/manual/nix-build.1
  GEN    doc/manual/nix-shell.1
  GEN    doc/manual/nix-store.1
  GEN    doc/manual/nix-instantiate.1
  GEN    doc/manual/nix-collect-garbage.1
  GEN    doc/manual/nix-prefetch-url.1
  GEN    doc/manual/nix-channel.1
  GEN    doc/manual/nix-hash.1
  GEN    doc/manual/nix-copy-closure.1
  LD     /usr/local/lib/
ld: error: cannot open output file /usr/local/lib/ Permission denied
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

This seems wrong, make all should never write outside the build directory.

As far as I understand the makefiles, this is done (in the instance shown above) to inject an rpath value into the final nix executable. I would like to understand why that is necessary. Or if it is not necessary, what is the rationale?

Perhaps this step can be made optional.

Or perhaps building everything statically will avoid this problem completely. I might try that anyway.


I’m not sure why this is the case, but you’d probably have more luck asking in the Nix issue tracker than here