How to look at the build directory after successful build

I’d like to look at the build directory after a successful build. nix-build has --keep-failed option to preserve the build directory when the build fails, but this option does not work for successful builds.

Context: I’d like to test whether my patch fixes the issue by checking the content of the build directory after the build. However, I couldn’t keep the build directory because the builds are succeeding.

3 Likes

I still don’t know how to preserve the build directory after a successful build, but I found a workaround via nix-shell.
For example, if you want to reproduce the build directory after building hello, you can run genericBuild inside nix-shell '<nixpkgs>' -A hello:

/tmp$ nix-shell '<nixpkgs>' -A hello
this path will be fetched (0.69 MiB download, 0.69 MiB unpacked):
  /nix/store/3x7dwzq014bblazs7kq20p9hyzz0qh8g-hello-2.10.tar.gz
copying path '/nix/store/3x7dwzq014bblazs7kq20p9hyzz0qh8g-hello-2.10.tar.gz' from 'https://cache.nixos.org'...

[nix-shell:/tmp]$ genericBuild
<build log>

[nix-shell:/tmp/hello-2.10]$ ls
ABOUT-NLS  COPYING    ChangeLog.O  INSTALL   Makefile.am  NEWS    README-dev      THANKS  aclocal.m4  config.h   config.log     configure     contrib  hello    lib  maint.mk  po   stamp-h1        tests
AUTHORS    ChangeLog  GNUmakefile  Makefile  Makefile.in  README  README-release  TODO    build-aux   config.in  config.status  configure.ac  doc      hello.1  m4   man       src  test-suite.log

nativeBuildInputs = [ keepBuildTree ]; seems to work (which I just learned about from Use of $NIX_BUILD_TOP considered harmful · Issue #189691 · NixOS/nixpkgs · GitHub).

1 Like