How to bulid all outputs of a derivation with `nix-build`

Mostly when debugging things I run nix-build on derivations directly:

~ $ nix-build /nix/store/z5yb5w0yjclf2bwgjxll3pzwdbgqsw13-kaleidogen-lambda-0.1.0.0.drv --substituters 'https://kaleidogen.cachix.org/'
these paths will be fetched (1.56 MiB download, 6.74 MiB unpacked):
  /nix/store/4vc5wc4nmg497ywk05isa5q1lz7ac58b-kaleidogen-lambda-0.1.0.0
copying path '/nix/store/4vc5wc4nmg497ywk05isa5q1lz7ac58b-kaleidogen-lambda-0.1.0.0' from 'https://kaleidogen.cachix.org'...
/nix/store/4vc5wc4nmg497ywk05isa5q1lz7ac58b-kaleidogen-lambda-0.1.0.0

In this case, the derivation has multiple outputs (out and doc), but as you can see it builds only one of them.

Which invocation of nix-build will tell it to build all, or a specific output, of a given derivation?

Guess I found it out myself, so sharing it here stackexchange-style:

This seems to work:

~ $ nix-build -E '(import /nix/store/z5yb5w0yjclf2bwgjxll3pzwdbgqsw13-kaleidogen-lambda-0.1.0.0.drv).doc' --substituters 'https://kaleidogen.cachix.org/'
these paths will be fetched (0.00 MiB download, 0.00 MiB unpacked):
  /nix/store/9aq44qjdyrhk6ks6f7ffxx21ysvzivw6-kaleidogen-lambda-0.1.0.0-doc
copying path '/nix/store/9aq44qjdyrhk6ks6f7ffxx21ysvzivw6-kaleidogen-lambda-0.1.0.0-doc' from 'https://kaleidogen.cachix.org'...
/nix/store/9aq44qjdyrhk6ks6f7ffxx21ysvzivw6-kaleidogen-lambda-0.1.0.0-doc
2 Likes