Nix build - evaluating expressions

I am trying to use the new nix command to build the result of an expression. The release notes suggest

nix build '(with import <nixpkgs> {}; hello)'

That works fine, but it doesn’t work well with the -f flag. If I specify a different version of nixpkgs, <nixpkgs> still resolves to the normal one I usually use.

nix build -f /path/to/nixpkgs '(with import <nixpkgs> {}; hello)'

Of course, specifying an attribute does work but that’s not flexible enough for me.

nix build -f /path/to/nixpkgs hello

How do I refer to the “correct” version of nixpkgs in the expression?

Is there some official documentation which explains how all the new nix commands work? Am I supposed to be using the old ones or the new ones.

Cheers,

Matt

I have since found an answer to my question but I don’t find it very satisfactory.

nix build -I nixpkgs=/path/to/nixpkgs '(with import <nixpkgs> {}; hello)'

In particular, it is incidental that what I intend to build in this case is a complete package set.
My ideal interface would have been:

nix build -f /path/to/nixpkgs -E "res: res.hello"

The argument to the -E flag is an expression which takes the result of evaluating the file
as an argument. This is a slight generalisation of the behaviour of the -A flag.

Is there some official documentation which explains how all the new nix commands work? Am I supposed to be using the old ones or the new ones.

@Infinisil answered these questions in IRC for me. He said that the only documentation for the nix commands was by the --help flag and that many people were still using the old commands. The interface for the new commands seems nicer but the lack of documentation makes them challenging to use. In particular, the behaviour of how nix build decided how to build an argument was confusing to me. It was not intuitive that a string starting with a ( was
evaluated as an expression.

nix build -E '(with import /path/to/nixpkgs {}; hello)'

Is the other option I mentioned