Using nix develop to debug builds

When packaging software in nixpkgs I often run into situations where the build takes a long time, but I need to do some ad-hoc experimenting during the postInstall. This is quite cumbersome to go through all the phases using nix build for each change I try.

I think that nix develop is the command to use for these cases, but it is unclear to me how I can use it to actually reproduce the steps that nix build is using.

From what I gathered so far I use the following steps:

$ nix develop --ignore-environment .#hello
$ unpackPhase

From here I need to look up what directory unpackPhase actually created. I used ls for that:

$ ls
... different directories from nixpkgs ...
hello-2.12.1
...
$ cd hello-2.12.1

From here it is a bit unclear, as I don’t know for sure what phases an arbitrary package has. $phases doesn’t exist, so I try the usual suspects:

  • patchPhase
  • configurePhase
  • buildPhase

This results in an error:

build flags: SHELL=/run/current-system/sw/bin/fish

It was using my systems shell, instead of the one that is needed for the build. I did use --ignore-environment, so I’m not sure why the SHELL variable unintendedly got in there.

I use export SHELL=$(command -v bash) to circumvent this.

For packages that have additional phases I have run into cases where I missed one of them (from top of my mind cargo?).

Seeing this experience being less than ideal, what is the intended way to use nix develop or debug a build in general?

Considering that nix-shell -A hello correctly changes $SHELL (but nix develop doesn’t), this seems like a bug to me, so I’d suggest to file a bug against Nix.

Thanks! I’ve submitted the issue here: `nix develop` does not set `SHELL` correctly · Issue #7971 · NixOS/nix · GitHub

That said, it’s still unclear to me how nix develop should work if this problem didn’t pop up :sweat_smile:

1 Like

this might help you

then again, it may not.

1 Like