These instructions describe how to get an interactive shell at the point in a derivation when the derivation fails.
This works in a Linux single-user installation of Nix.
breakpointHook package to the
nativeBuildInputs of a
nativeBuildInputs = [ breakpointHook ];
nix-env -i cntr
Run your Nix build command, and when it fails, the breakpointHook will output
a message like this:
build failed in installPhase with exit code 1 To attach install cntr and run the following command as root: cntr attach -t command cntr-/nix/store/6vwxqrwq5h1fd3nw4mc61wgk7rppn2qw-jupyterlab-extended
So we run that command as root. The root user doesn’t have a
PATH to the
cntr command which we installed in our Nix profile, so give it the full path to our single-user-installed
sudo /home/$USER/.nix-profile/bin/cntr attach -t command cntr-/nix/store/6vwxqrwq5h1fd3nw4mc61wgk7rppn2qw-jupyterlab-extended
And now we’re in the sleeping Nix container. From here, run
cntr exec to fully load the build environment.
$TMPDIR directory is where Nix has created the temporary directory for the build.
Now we are fully inside the context of the build, and any commands which we
enter in the shell will be as if we had entered that command on a line
in the phase (for example,
buildPhase) of our derivation when the derivation failed.
There is a subsection on breakpointHook in the nixpkgs manual section 6.7 Package setup hooks