Log from failed derivation

Is there a way to get the log from a failed derivation, using nix log or something like it?

Also: Is there a way to configure nix to log all simplified bash command during the build phase, as in the bash set -x builtin?

1 Like

Does nix not give you a handy copy-pastable command involving nix log to run at the end of the build? It does for me - what version are you using? I get this, for example (look at the last line):

tlater ~/Documents/Projects/tlaterpkgs $ nix build .#eontimer
warning: Git tree '/home/tlater/Documents/Projects/tlaterpkgs' is dirty
error: builder for '/nix/store/3kn3qlnrjxjrdb3hnabmbp9mc8vfw7k0-eontimer-d53e42a508de4003b719791ce36e37a8f49dbfc9.drv' failed with exit code 1;
       last 10 log lines:
       >     CMAKE_INSTALL_LOCALEDIR
       >     CMAKE_INSTALL_MANDIR
       >     CMAKE_INSTALL_OLDINCLUDEDIR
       >     CMAKE_INSTALL_SBINDIR
       >     CMAKE_POLICY_DEFAULT_CMP0025
       >
       >
       > -- Build files have been written to: /build/source/build
       > cmake: enabled parallel building
       > building
       For full logs, run 'nix log /nix/store/3kn3qlnrjxjrdb3hnabmbp9mc8vfw7k0-eontimer-d53e42a508de4003b719791ce36e37a8f49dbfc9.drv'.

nix build -L will also log the commands as they are happening, which oddly enough doesn’t appear to be documented anywhere.

Does nix not give you a handy copy-pastable command involving nix log to run at the end of the build? It does for me - what version are you using?

Yeah it should, shouldn’t it? I’m not getting that though. The last lines of stderr look like this:

onnxruntime> make: *** [Makefile:124: test] Error 8
error: builder for '/nix/store/7h7g04zj19xld7w37aymhr4xd3785p9v-onnxruntime-1.10.0.drv' failed with exit code 2
error: 1 dependencies of derivation '/nix/store/vqf3szh2dh95hqb1krn6sxq06dvz7jww-vskserver-1.0.0.drv' failed to build

I’m on Nix 2.4, single-user installation. I’ll upgrade to 2.6 and see if it’s different.

(When I nix log /nix/store/7h7g04zj19xld7w37aymhr4xd3785p9v-onnxruntime-1.10.0.drv then it starts building some derivation instead of giving me the logs… ?)

On Nix 2.6 it still doesn’t prompt me to run nix log /nix/store/7h7g04zj19xld7w37aymhr4xd3785p9v-onnxruntime-1.10.0.drv, but when I run that command it correctly shows the log, so, whatever. Maybe I was doing something wrong before.

Thx @TLATER !

1 Like

I definitely recall this being a feature added at some point, so it may only be present in 2.5+. A little feature matrix somewhere might be nice, and we should really add docs for -L, but at least you have some log access now.

For some reason, the -L feature is documented in nix help, rather than nix help build. I suppose it is because it can be used by some other commands?

Ah, guess that’s why I know about that flag. That makes sense, but is a bit awkward from a user perspective; if I’m trying to build something I’m going to look at help for nix build, and showing logs is an especially build-related feature.

Not sure how to do this any better though, documenting overall flags for each subcommand risks just having too much to read, so it would need to be a bit more discriminatory than that. Maybe a hint to use the -L flag could be added to the nix log hint?

Honestly, I mostly grep through man pages, so I’m not too worried about their length. Therefore, I’d prefer if common options were repeated in each manpage.