How to profile/debug slow nix-instantiate times

I have a pretty complex set of nix expressions, and currently even when rebuilding the same thing twice in a row, I get a waiting time of at least 15 seconds.

Upon running just nix-instantiate I understood that it is this step that takes the time (obviously perhaps).

Besides going through all of the nix code and hypothesizing, Is there any way of profiling how long it takes to instantiate different expressions? (Besides propagating them to the top-level set and checking each one individually) Is there any approach in general that is recommended for this?

Thanks!

There’s NIX_SHOW_STATS=1 and NIX_COUNT_CALLS=1.

For generating flame graphs see nix.conf - Nix Reference Manual

2 Likes

Sounds promising!

I shall try both the environment variables and the flame graphs. Thanks!