Skip to content

Commit

Permalink
nix-env: add --outputs flag
Browse files Browse the repository at this point in the history
This isn't particularly useful since the json output already includes
metadata.  However the evaluation behaves differently, in this case
`meta.outputsToInstall` is also validated.  The same is done by the
channel index generation but it's currently not exposed in a way other
tools like ofborg could use it.

https://github.com/NixOS/nixos-channel-scripts/blob/7a681103b2b3ce150f7f96394f19aa0ad4797ca1/generate-programs-index.cc#L110
  • Loading branch information
LnL7 committed May 10, 2020
1 parent b92f58f commit 8ac5d67
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doc/manual/command-ref/nix-env.xml
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ $ nix-env --set-flag priority 10 gcc</screen>
<arg><option>--system</option></arg>
<arg><option>--drv-path</option></arg>
<arg><option>--out-path</option></arg>
<arg><option>--outputs</option></arg>
<arg><option>--description</option></arg>
<arg><option>--meta</option></arg>

Expand Down Expand Up @@ -1144,6 +1145,14 @@ user environment elements, etc. -->

</varlistentry>

<varlistentry><term><option>--outputs</option></term>

<listitem><para>Print the outputs of the derivation.
Unlike <option>--out-path</option>, only the outputs that would be installed are
listed.</para></listitem>

</varlistentry>

<varlistentry><term><option>--description</option></term>

<listitem><para>Print a short (one-line) description of the
Expand Down
12 changes: 12 additions & 0 deletions src/nix-env/nix-env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
bool printSystem = false;
bool printDrvPath = false;
bool printOutPath = false;
bool printOutputs = false;
bool printDescription = false;
bool printMeta = false;
bool compareVersions = false;
Expand All @@ -913,6 +914,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
else if (arg == "--compare-versions" || arg == "-c") compareVersions = true;
else if (arg == "--drv-path") printDrvPath = true;
else if (arg == "--out-path") printOutPath = true;
else if (arg == "--outputs") printOutputs = true;
else if (arg == "--meta") printMeta = true;
else if (arg == "--installed") source = sInstalled;
else if (arg == "--available" || arg == "-a") source = sAvailable;
Expand Down Expand Up @@ -1096,6 +1098,16 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
columns.push_back(s);
}

if (printOutputs && !xmlOutput) {
DrvInfo::Outputs outputs = i.queryOutputs(true);
string s;
for (auto & j : outputs) {
if (!s.empty()) s += ';';
s += j.first;
}
columns.push_back(s);
}

if (printDescription) {
string descr = i.queryMetaString("description");
if (xmlOutput) {
Expand Down

0 comments on commit 8ac5d67

Please sign in to comment.