Use of $NIX_BUILD_TOP considered harmful?

Hi folks,

After (" buildRustPackage breaks with keepBuildTree or in nix-shell") being idle for a year, I made a more general issue (“Use of $NIX_BUILD_TOP considered harmful”) and thought I’d post here for more visibility.

What do you think?

1 Like

I think buildRustOPackage just needs proper support for keepBuildTree and I would guess that using relative directories would create the same issue.

But generally $NIX_BUILD_TOP must be used instead of /build and should be avoided if possible which is not always easy or handy.

In the case of buildRustPackage this happens in postPatchHooks though, I think we can rely on sourceRoot being set correctly (and with that pwd as well) instead. That’s already done in other places in that hook as well, see Relative paths are not an issue because we can realpath when setting the variables.

It does not look like NIX_BUILD_TOP is required at all, I will be opening a PR fixing this later.

1 Like

Opened said PR, executing from a nix-shell and keepBuildTree work fine with it from my testing :+1:

1 Like

I should’ve targeted staging instead for this. Since I had a few commits in the same PR that didn’t cause any rebuilds, I opened a separate PR to fix the NIX_BUILD_TOP problem: