Is there a nix command (either old or new) that attempts to build a derivation, and, if this fails, it drops you into an interactive shell with the failed build’s environment? As-if you had manually typed the commands for all the steps up to the point where the build failed.
If this existed, it would allow people to debug build failures without having to remind themselves of all the steps they need to take to unpack, patch, etc. Compare sourcehut’s CI runners letting you ssh into the build VM if the build fails, which is such a killer feature that I tell people to use sourcehut just for that.
To use that, it appears to be necessary to modify the nativeBuildInputs of the derivation that’s being debugged. Is there any way to get the same effect from the nix command line, without modifying the derivation at all?
Investigating a little more, nix build already has a --debugger option that does what I’m looking for, but it doesn’t seem to be available to the traditional nix-* commands. I do not have time in the foreseeable future to write a patch myself. However, I filed an issue so this doesn’t get forgotten about: Make `nix build --debugger` available in `nix-build` as well · Issue #16181 · NixOS/nix · GitHub
Ugh, I keep forgetting that when the nix manual says “evaluation” it means just evaluation of nix expressions and not any intertwined build operations. I revised the issue.
The parentheses are a safeguard against exiting the shell on failure; I don’t know why it does that sometimes. As far as I can tell set -o shows errexit: off…
EDIT: I should also specify that genericBuild is a stdenv thing, but most packages are written with stdenv so this is still broadly applicable
this is my typical workflow, just play with the phases variable, i.e. get to build and then repeatedly run build. ofc, there are some classes of error that this won’t cover, but it get most of them. There is also nix-build --keep-failed which is often good enough to get through trivial problems.