Very quick newbie question on nix-shell

Hello everyone

I’m building a derivation using nix-shell, since I would like the build folder to stay available even after the build process. So I opened a nix-shell and ran genericBuild. The process completed successfully, installPhase included, and in fact I can see the correct output path and the .drv file in the nix store.

When I try to use the built derivation as an input to something else, however, nix always behaves as if it had never built it and tries to build it again. I checked and it’s trying to build the vary same derivation, the store paths match and so does the output of nix show-derivation.

What am I missing? Do I need to “register” the newly built derivation somewhere for nix to understand it exists?

Thanks in advance.

No, that should be automatic. Perhaps something is placing/changing files in a directory that is also listed as one of the inputs for your nix-shell configuration?

That’s possible I suppose. Still, it would be strange since it’s just a cmake based derivation… Weirdest thing it does is placing the build dir alongside the source dir instead of inside, since that’s what the project requires, but it does that from inside mkDerivation.

The install manifest shows no path outside the output directory.

Is there a way to debug why nix thinks it needs to rebuild the derivation?

I’m pretty sure that anything other than actually letting Nix run the build will not properly register it. Running the build manually inside nix-shell is not a supported usecase. So from Nix’s perspective you haven’t built it, so it needs to do the build itself.

(Why not? Well, you could have run who knows what inside that shell - in order to guarantee that the build really was run in the standard way we need to let Nix run it.)

Running genericBuild inside nix-shell shouldn’t even be able to put things in the store. Unless you’re running as root or as some user who has permissions to modify the Nix store? If so, please don’t do that, it’s very dangerous!

It’s a single user installation, doesn’t the installer tell you to run

mkdir -m 0755 /nix && chown your_username /nix

as root if it does not find /nix in your computer?
As that is what I did, my user has very much the ability to write inside the store.
Is that wrong?

Shame about nix-shell not working, but I understand the reasoning.