Merge pull request #815 from vcunat/p/outputsToInstall

nix-env: respect meta.outputsToInstall
This commit is contained in:
Eelco Dolstra 2016-04-14 20:55:41 +02:00
commit 31a1a8ed3c
4 changed files with 28 additions and 7 deletions

View file

@ -367,6 +367,10 @@ number of possible ways:
linkend="rsec-nix-store-realise">realised</link> and linkend="rsec-nix-store-realise">realised</link> and
installed.</para></listitem> installed.</para></listitem>
<listitem><para>By default all outputs are installed for each derivation.
That can be reduced by setting <literal>meta.outputsToInstall</literal>.
</para></listitem> <!-- TODO: link nixpkgs docs on the ability to override those. -->
</itemizedlist> </itemizedlist>
</para> </para>

View file

@ -30,7 +30,7 @@ string DrvInfo::queryOutPath()
} }
DrvInfo::Outputs DrvInfo::queryOutputs() DrvInfo::Outputs DrvInfo::queryOutputs(bool onlyOutputsToInstall)
{ {
if (outputs.empty()) { if (outputs.empty()) {
/* Get the outputs list. */ /* Get the outputs list. */
@ -55,7 +55,23 @@ DrvInfo::Outputs DrvInfo::queryOutputs()
} else } else
outputs["out"] = queryOutPath(); outputs["out"] = queryOutPath();
} }
return outputs; if (!onlyOutputsToInstall || !attrs)
return outputs;
/* Check for `meta.outputsToInstall` and return `outputs` reduced to that. */
const Value * outTI = queryMeta("outputsToInstall");
if (!outTI) return outputs;
const auto errMsg = Error("this derivation has bad meta.outputsToInstall");
/* ^ this shows during `nix-env -i` right under the bad derivation */
if (!outTI->isList()) throw errMsg;
Outputs result;
for (auto i = outTI->listElems(); i != outTI->listElems() + outTI->listSize(); ++i) {
if ((*i)->type != tString) throw errMsg;
auto out = outputs.find((*i)->string.s);
if (out == outputs.end()) throw errMsg;
result.insert(*out);
}
return result;
} }
@ -192,8 +208,8 @@ typedef set<Bindings *> Done;
/* Evaluate value `v'. If it evaluates to a set of type `derivation', /* Evaluate value `v'. If it evaluates to a set of type `derivation',
then put information about it in `drvs' (unless it's already in then put information about it in `drvs' (unless it's already in `done').
`doneExprs'). The result boolean indicates whether it makes sense The result boolean indicates whether it makes sense
for the caller to recursively search for derivations in `v'. */ for the caller to recursively search for derivations in `v'. */
static bool getDerivation(EvalState & state, Value & v, static bool getDerivation(EvalState & state, Value & v,
const string & attrPath, DrvInfos & drvs, Done & done, const string & attrPath, DrvInfos & drvs, Done & done,

View file

@ -42,7 +42,8 @@ public:
string queryDrvPath(); string queryDrvPath();
string queryOutPath(); string queryOutPath();
string queryOutputName(); string queryOutputName();
Outputs queryOutputs(); /** Return the list of outputs. The "outputs to install" are determined by `mesa.outputsToInstall`. */
Outputs queryOutputs(bool onlyOutputsToInstall = false);
StringSet queryMetaNames(); StringSet queryMetaNames();
Value * queryMeta(const string & name); Value * queryMeta(const string & name);

View file

@ -63,8 +63,8 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
if (drvPath != "") if (drvPath != "")
mkString(*state.allocAttr(v, state.sDrvPath), i.queryDrvPath()); mkString(*state.allocAttr(v, state.sDrvPath), i.queryDrvPath());
// Copy each output. // Copy each output meant for installation.
DrvInfo::Outputs outputs = i.queryOutputs(); DrvInfo::Outputs outputs = i.queryOutputs(true);
Value & vOutputs = *state.allocAttr(v, state.sOutputs); Value & vOutputs = *state.allocAttr(v, state.sOutputs);
state.mkList(vOutputs, outputs.size()); state.mkList(vOutputs, outputs.size());
unsigned int m = 0; unsigned int m = 0;