# Debugging Build Failures

At the beginning of each phase of the build (such as unpacking, building or installing), the set of all shell variables is written to the file `env-vars` at the top-level build directory. This is useful for debugging: it allows you to recreate the environment in which a build was performed. For instance, if a build fails, then assuming you used the `-K` flag, you can go to the output directory and switch to the environment of the builder:

    $ nix-build -K ./foo.nix
    ... fails, keeping build directory `/tmp/nix-1234-0'

    $ cd /tmp/nix-1234-0

    $ source env-vars

    (edit some files...)

    $ make

    (execution continues with the same GCC, make, etc.)