diff --git a/doc/manual/command-ref/nix-env.xml b/doc/manual/command-ref/nix-env.xml index d257a5e49c70d37d35a2b836d6699fbef1df5479..9c03ccce11c49714a9899853fc3639959e26d40f 100644 --- a/doc/manual/command-ref/nix-env.xml +++ b/doc/manual/command-ref/nix-env.xml @@ -1066,7 +1066,8 @@ user environment elements, etc. --> the derivation, which can be used to unambiguously select it using the <link linkend="opt-attr"><option>--attr</option> option</link> available in commands that install derivations like - <literal>nix-env --install</literal>.</para></listitem> + <literal>nix-env --install</literal>. This option only works + together with <option>--available</option></para></listitem> </varlistentry> diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index a40d0c7e6e511d6841916ace94f8d210773c0598..106dfe0b6d89a8f0e8c1f9f676e71607d36cf909 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -914,6 +914,8 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) throw UsageError(format("unknown flag '%1%'") % arg); } + if (printAttrPath && source != sAvailable) + throw UsageError("--attr-path(-P) only works with --available"); /* Obtain derivation information from the specified source. */ DrvInfos availElems, installedElems;