Open
Description
Describe the bug
I can't figure out the equivalent for many nix-instantiate
commands. Another bug #???? describes how nix eval
and nix eval --{raw|json}
behave differently. And the latter that works for me, returns the out path, rather than the derivation (this feels similar to how nix copy aggressively builds instead of just copying drvs #3696).
How do I get the drv path for a flake output? This is what I have now, I don't like it:
function instantiate() {
machine="${1}"; shift
# do it
true
#drv="$(nix eval --pure-eval ".#nixosConfigurations.${machine}.config.system.build.toplevel")" # TODO: why????
set -e
drv="$(set -eu; nix --experimental-features 'nix-command flakes' --pure-eval \
eval \
--raw ".#machines.${machine}")"
drv="$(set -euo pipefail; nix --experimental-features 'nix-command flakes' --pure-eval \
show-derivation "${drv}" | jq -r 'to_entries[].key')"
echo -e "${drv}"
}
nix (Nix) 2.4pre20200721_ff314f1
EDIT (workaround)
You can do something like this instead:
thing=".#packages.x86_64-linux.testPackage" # pkg example
thing=".#nixosConfigurations.yourHostName.config.system.build.toplevel" # nixos cfg example
nix build \
--experimental-features 'nix-command flakes' \
"${thing}.drvPath"
This gives you a /nix/store/abc123..thing.drv
path that you can then nix copy --derivation
or nix-copy-closure
to a remote machine to build, etc.