diff --git a/src/libexpr/get-drvs.cc b/src/libexpr/get-drvs.cc index 6670d0636a1..f3381aa75ea 100644 --- a/src/libexpr/get-drvs.cc +++ b/src/libexpr/get-drvs.cc @@ -6,6 +6,29 @@ namespace nix { +string DrvInfo::queryName(EvalState & state) const +{ + if (name == "" && attrs) { + Bindings::iterator i = attrs->find(state.sName); + (string &) name = state.forceStringNoCtx(*i->value); + } + return name; +} + + +string DrvInfo::querySystem(EvalState & state) const +{ + if (system == "" && attrs) { + Bindings::iterator i = attrs->find(state.sSystem); + if (i == attrs->end()) + (string &) system = "unknown"; + else + (string &) system = state.forceStringNoCtx(*i->value); + } + return system; +} + + string DrvInfo::queryDrvPath(EvalState & state) const { if (drvPath == "" && attrs) { @@ -27,12 +50,35 @@ string DrvInfo::queryOutPath(EvalState & state) const return outPath; } +static MetaValue createMetaValue(EvalState & state, Value & v) +{ + MetaValue value; + try { + state.forceValue(v); + if (v.type == tString) { + value.type = MetaValue::tpString; + value.stringValue = v.string.s; + } else if (v.type == tInt) { + value.type = MetaValue::tpInt; + value.intValue = v.integer; + } else if (v.type == tList) { + value.type = MetaValue::tpStrings; + for (unsigned int j = 0; j < v.list.length; ++j) + value.stringValues.push_back(state.forceStringNoCtx(*v.list.elems[j])); + } else + value.type = MetaValue::tpNone; + } catch (ImportReadOnlyError & e) { + value.type = MetaValue::tpNone; + } + return value; +} MetaInfo DrvInfo::queryMetaInfo(EvalState & state) const { if (metaInfoRead) return meta; (bool &) metaInfoRead = true; + ((MetaInfo &) meta).clear(); Bindings::iterator a = attrs->find(state.sMeta); if (a == attrs->end()) return meta; /* fine, empty meta information */ @@ -40,20 +86,8 @@ MetaInfo DrvInfo::queryMetaInfo(EvalState & state) const state.forceAttrs(*a->value); foreach (Bindings::iterator, i, *a->value->attrs) { - MetaValue value; - state.forceValue(*i->value); - if (i->value->type == tString) { - value.type = MetaValue::tpString; - value.stringValue = i->value->string.s; - } else if (i->value->type == tInt) { - value.type = MetaValue::tpInt; - value.intValue = i->value->integer; - } else if (i->value->type == tList) { - value.type = MetaValue::tpStrings; - for (unsigned int j = 0; j < i->value->list.length; ++j) - value.stringValues.push_back(state.forceStringNoCtx(*i->value->list.elems[j])); - } else continue; - ((MetaInfo &) meta)[i->name] = value; + MetaValue value = createMetaValue(state, *i->value); + if (value.type != MetaValue::tpNone) ((MetaInfo &) meta)[i->name] = value; } return meta; @@ -62,8 +96,19 @@ MetaInfo DrvInfo::queryMetaInfo(EvalState & state) const MetaValue DrvInfo::queryMetaInfo(EvalState & state, const string & name) const { - /* !!! evaluates all meta attributes => inefficient */ - return queryMetaInfo(state)[name]; + if (metaInfoRead) return ((MetaInfo &)meta)[name]; + if (meta.count(name)) return ((MetaInfo &)meta)[name]; + + Bindings::iterator m = attrs->find(state.sMeta); + if (m == attrs->end()) return ((MetaInfo &)meta)[name]; + + state.forceAttrs(*m->value); + Bindings::iterator i = m->value->attrs->find(state.symbols.create(name)); + if (i == m->value->attrs->end()) return ((MetaInfo &)meta)[name]; + MetaValue value = createMetaValue(state, *i->value); + if (value.type != MetaValue::tpNone) ((MetaInfo &) meta)[name] = value; + + return ((MetaInfo &)meta)[name]; } @@ -100,13 +145,6 @@ static bool getDerivation(EvalState & state, Value & v, Bindings::iterator i = v.attrs->find(state.sName); /* !!! We really would like to have a decent back trace here. */ if (i == v.attrs->end()) throw TypeError("derivation name missing"); - drv.name = state.forceStringNoCtx(*i->value); - - Bindings::iterator i2 = v.attrs->find(state.sSystem); - if (i2 == v.attrs->end()) - drv.system = "unknown"; - else - drv.system = state.forceStringNoCtx(*i2->value); drv.attrs = v.attrs; @@ -117,6 +155,8 @@ static bool getDerivation(EvalState & state, Value & v, } catch (AssertionError & e) { return false; + } catch (ImportReadOnlyError & e) { + return false; } } diff --git a/src/libexpr/get-drvs.hh b/src/libexpr/get-drvs.hh index 25d8baa559b..b0176d958ee 100644 --- a/src/libexpr/get-drvs.hh +++ b/src/libexpr/get-drvs.hh @@ -26,6 +26,8 @@ typedef std::map MetaInfo; struct DrvInfo { private: + string name; + string system; string drvPath; string outPath; @@ -35,20 +37,30 @@ private: bool failed; // set if we get an AssertionError public: - string name; string attrPath; /* path towards the derivation */ - string system; /* !!! make this private */ Bindings * attrs; DrvInfo() : metaInfoRead(false), failed(false), attrs(0) { }; + string queryName(EvalState & state) const; + string querySystem(EvalState & state) const; string queryDrvPath(EvalState & state) const; string queryOutPath(EvalState & state) const; MetaInfo queryMetaInfo(EvalState & state) const; MetaValue queryMetaInfo(EvalState & state, const string & name) const; + void setName(const string & s) + { + name = s; + } + + void setSystem(const string & s) + { + system = s; + } + void setDrvPath(const string & s) { drvPath = s; diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index bc6c3287c79..0eac3d69d88 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -16,6 +16,7 @@ MakeError(ThrownError, AssertionError) MakeError(Abort, EvalError) MakeError(TypeError, EvalError) MakeError(ImportError, EvalError) // error building an imported derivation +MakeError(ImportReadOnlyError, EvalError) // error when trying to import a derivation in read-only mode /* Position objects. */ diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index d3809e6984a..7189465af93 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -45,24 +45,41 @@ static void prim_import(EvalState & state, Value * * args, Value & v) foreach (PathSet::iterator, i, context) { Path ctx = decodeContext(*i).first; + string outputName = decodeContext(*i).second; assert(isStorePath(ctx)); - if (!store->isValidPath(ctx)) - throw EvalError(format("cannot import `%1%', since path `%2%' is not valid") - % path % ctx); - if (isDerivation(ctx)) - try { - /* For performance, prefetch all substitute info. */ - PathSet willBuild, willSubstitute, unknown; - unsigned long long downloadSize, narSize; - queryMissing(*store, singleton(ctx), - willBuild, willSubstitute, unknown, downloadSize, narSize); + if (!store->isValidPath(ctx)) { + if (outputName.empty()) + throw EvalError(format("cannot import `%1%', since path `%2%' is not valid") + % path % ctx); + else + throw ImportReadOnlyError(format("cannot import `%1%', since path `%2%' cannot be written to the store in read-only mode") + % path % ctx); + } + if (isDerivation(ctx)) { + Derivation drv = derivationFromPath(*store, ctx); + + if (outputName.empty() || + !store->isValidPath(drv.outputs[outputName].path)) { + if (settings.readOnlyMode) + foreach (DerivationOutputs::iterator, j, drv.outputs) + if (!store->isValidPath(j->second.path)) + throw ImportReadOnlyError(format("cannot import `%1%', since derivation `%2%' cannot be realised in read-only mode") + % path % ctx); + try { + /* For performance, prefetch all substitute info. */ + PathSet willBuild, willSubstitute, unknown; + unsigned long long downloadSize, narSize; + queryMissing(*store, singleton(ctx), + willBuild, willSubstitute, unknown, downloadSize, narSize); - /* !!! If using a substitute, we only need to fetch - the selected output of this derivation. */ - store->buildPaths(singleton(ctx)); - } catch (Error & e) { - throw ImportError(e.msg()); + /* !!! If using a substitute, we only need to fetch + the selected output of this derivation. */ + store->buildPaths(singleton(ctx)); + } catch (Error & e) { + throw ImportError(e.msg()); + } } + } } if (isStorePath(path) && store->isValidPath(path) && isDerivation(path)) { diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index 5174daf90d8..218a646bee2 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -173,7 +173,7 @@ static void loadDerivations(EvalState & state, Path nixExprPath, system. */ for (DrvInfos::iterator i = elems.begin(), j; i != elems.end(); i = j) { j = i; j++; - if (systemFilter != "*" && i->system != systemFilter) + if (systemFilter != "*" && i->querySystem(state) != systemFilter) elems.erase(i); } } @@ -217,9 +217,13 @@ static bool isPrebuilt(EvalState & state, const DrvInfo & elem) { assert(false); #if 0 - return - store->isValidPath(elem.queryOutPath(state)) || - store->hasSubstitutes(elem.queryOutPath(state)); + try { + return + store->isValidPath(elem.queryOutPath(state)) || + store->hasSubstitutes(elem.queryOutPath(state)); + } catch (ImportReadOnlyError & e) { + return false; + } #endif } @@ -241,7 +245,7 @@ static DrvInfos filterBySelector(EvalState & state, const DrvInfos & allElems, for (DrvInfos::const_iterator j = allElems.begin(); j != allElems.end(); ++j, ++n) { - DrvName drvName(j->name); + DrvName drvName(j->queryName(state)); if (i->matches(drvName)) { i->hits++; matches.push_back(std::pair(*j, n)); @@ -263,35 +267,35 @@ static DrvInfos filterBySelector(EvalState & state, const DrvInfos & allElems, StringSet multiple; for (Matches::iterator j = matches.begin(); j != matches.end(); ++j) { - DrvName drvName(j->first.name); + DrvName drvName(j->first.queryName(state)); int d = 1; Newest::iterator k = newest.find(drvName.name); if (k != newest.end()) { - d = j->first.system == k->second.first.system ? 0 : - j->first.system == settings.thisSystem ? 1 : - k->second.first.system == settings.thisSystem ? -1 : 0; + d = j->first.querySystem(state) == k->second.first.querySystem(state) ? 0 : + j->first.querySystem(state) == settings.thisSystem ? 1 : + k->second.first.querySystem(state) == settings.thisSystem ? -1 : 0; if (d == 0) d = comparePriorities(state, j->first, k->second.first); if (d == 0) - d = compareVersions(drvName.version, DrvName(k->second.first.name).version); + d = compareVersions(drvName.version, DrvName(k->second.first.queryName(state)).version); } if (d > 0) { newest[drvName.name] = *j; - multiple.erase(j->first.name); + multiple.erase(j->first.queryName(state)); } else if (d == 0) { - multiple.insert(j->first.name); + multiple.insert(j->first.queryName(state)); } } matches.clear(); for (Newest::iterator j = newest.begin(); j != newest.end(); ++j) { - if (multiple.find(j->second.first.name) != multiple.end()) + if (multiple.find(j->second.first.queryName(state)) != multiple.end()) printMsg(lvlInfo, format("warning: there are multiple derivations named `%1%'; using the first one") - % j->second.first.name); + % j->second.first.queryName(state)); matches.push_back(j->second); } } @@ -395,7 +399,7 @@ static void queryInstSources(EvalState & state, } else elem.setOutPath(path); - elem.name = name; + elem.setName(name); elems.push_back(elem); } @@ -469,8 +473,8 @@ static void installDerivations(Globals & globals, path is not the one we want (e.g., `java-front' versus `java-front-0.9pre15899'). */ if (globals.forceName != "") - i->name = globals.forceName; - newNames.insert(DrvName(i->name).name); + i->setName(globals.forceName); + newNames.insert(DrvName(i->queryName(globals.state)).name); } /* Add in the already installed derivations, unless they have the @@ -483,19 +487,19 @@ static void installDerivations(Globals & globals, DrvInfos allElems(newElems); foreach (DrvInfos::iterator, i, installedElems) { - DrvName drvName(i->name); + DrvName drvName(i->queryName(globals.state)); MetaInfo meta = i->queryMetaInfo(globals.state); if (!globals.preserveInstalled && newNames.find(drvName.name) != newNames.end() && !keep(meta)) printMsg(lvlInfo, - format("replacing old `%1%'") % i->name); + format("replacing old `%1%'") % i->queryName(globals.state)); else allElems.push_back(*i); } foreach (DrvInfos::iterator, i, newElems) - printMsg(lvlInfo, format("installing `%1%'") % i->name); + printMsg(lvlInfo, format("installing `%1%'") % i->queryName(globals.state)); printMissing(globals.state, newElems); @@ -547,7 +551,7 @@ static void upgradeDerivations(Globals & globals, /* Go through all installed derivations. */ DrvInfos newElems; foreach (DrvInfos::iterator, i, installedElems) { - DrvName drvName(i->name); + DrvName drvName(i->queryName(globals.state)); try { @@ -566,7 +570,7 @@ static void upgradeDerivations(Globals & globals, DrvInfos::iterator bestElem = availElems.end(); DrvName bestName; foreach (DrvInfos::iterator, j, availElems) { - DrvName newName(j->name); + DrvName newName(j->queryName(globals.state)); if (newName.name == drvName.name) { int d = comparePriorities(globals.state, *i, *j); if (d == 0) d = compareVersions(drvName.version, newName.version); @@ -594,12 +598,12 @@ static void upgradeDerivations(Globals & globals, { printMsg(lvlInfo, format("upgrading `%1%' to `%2%'") - % i->name % bestElem->name); + % i->queryName(globals.state) % bestElem->queryName(globals.state)); newElems.push_back(*bestElem); } else newElems.push_back(*i); } catch (Error & e) { - e.addPrefix(format("while trying to find an upgrade for `%1%':\n") % i->name); + e.addPrefix(format("while trying to find an upgrade for `%1%':\n") % i->queryName(globals.state)); throw; } } @@ -664,11 +668,11 @@ static void opSetFlag(Globals & globals, /* Update all matching derivations. */ foreach (DrvInfos::iterator, i, installedElems) { - DrvName drvName(i->name); + DrvName drvName(i->queryName(globals.state)); foreach (DrvNames::iterator, j, selectors) if (j->matches(drvName)) { printMsg(lvlInfo, - format("setting flag on `%1%'") % i->name); + format("setting flag on `%1%'") % i->queryName(globals.state)); setMetaFlag(globals.state, *i, flagName, flagValue); break; } @@ -726,7 +730,7 @@ static void uninstallDerivations(Globals & globals, Strings & selectors, DrvInfos newElems; foreach (DrvInfos::iterator, i, installedElems) { - DrvName drvName(i->name); + DrvName drvName(i->queryName(globals.state)); bool found = false; foreach (Strings::iterator, j, selectors) /* !!! the repeated calls to followLinksToStorePath() @@ -734,7 +738,7 @@ static void uninstallDerivations(Globals & globals, Strings & selectors, if ((isPath(*j) && i->queryOutPath(globals.state) == followLinksToStorePath(*j)) || DrvName(*j).matches(drvName)) { - printMsg(lvlInfo, format("uninstalling `%1%'") % i->name); + printMsg(lvlInfo, format("uninstalling `%1%'") % i->queryName(globals.state)); found = true; break; } @@ -764,12 +768,19 @@ static bool cmpChars(char a, char b) } -static bool cmpElemByName(const DrvInfo & a, const DrvInfo & b) +class cmpElemByName { - return lexicographical_compare( - a.name.begin(), a.name.end(), - b.name.begin(), b.name.end(), cmpChars); -} + public: + cmpElemByName(EvalState & state) : _state(state) { } + bool operator()(const DrvInfo & a, const DrvInfo & b) + { + return lexicographical_compare( + a.queryName(_state).begin(), a.queryName(_state).end(), + b.queryName(_state).begin(), b.queryName(_state).end(), cmpChars); + } + private: + EvalState & _state; +}; typedef list Table; @@ -814,16 +825,16 @@ void printTable(Table & table) typedef enum { cvLess, cvEqual, cvGreater, cvUnavail } VersionDiff; -static VersionDiff compareVersionAgainstSet( +static VersionDiff compareVersionAgainstSet(EvalState & state, const DrvInfo & elem, const DrvInfos & elems, string & version) { - DrvName name(elem.name); + DrvName name(elem.queryName(state)); VersionDiff diff = cvUnavail; version = "?"; for (DrvInfos::const_iterator i = elems.begin(); i != elems.end(); ++i) { - DrvName name2(i->name); + DrvName name2(i->queryName(state)); if (name.name == name2.name) { int d = compareVersions(name.version, name2.version); if (d < 0) { @@ -921,9 +932,10 @@ static void opQuery(Globals & globals, /* Sort them by name. */ /* !!! */ vector elems2; + cmpElemByName nameComparer(globals.state); for (DrvInfos::iterator i = elems.begin(); i != elems.end(); ++i) elems2.push_back(*i); - sort(elems2.begin(), elems2.end(), cmpElemByName); + sort(elems2.begin(), elems2.end(), nameComparer); /* We only need to know the installed paths when we are querying @@ -941,13 +953,18 @@ static void opQuery(Globals & globals, PathSet validPaths, substitutablePaths; if (printStatus) { PathSet paths; - foreach (vector::iterator, i, elems2) + foreach (vector::iterator, i, elems2) { + string name; try { + name = i->queryName(globals.state); paths.insert(i->queryOutPath(globals.state)); } catch (AssertionError & e) { - printMsg(lvlTalkative, format("skipping derivation named `%1%' which gives an assertion failure") % i->name); + printMsg(lvlTalkative, format("skipping derivation named `%1%' which gives an assertion failure") % name); i->setFailed(); + } catch (ImportReadOnlyError & e) { + printMsg(lvlTalkative, format("skipping derivation named `%1%' which gives an ImportReadOnly failure") % name); } + } validPaths = store->queryValidPaths(paths); substitutablePaths = store->querySubstitutablePaths(paths); } @@ -974,19 +991,23 @@ static void opQuery(Globals & globals, XMLAttrs attrs; if (printStatus) { - Path outPath = i->queryOutPath(globals.state); - bool hasSubs = substitutablePaths.find(outPath) != substitutablePaths.end(); - bool isInstalled = installed.find(outPath) != installed.end(); - bool isValid = validPaths.find(outPath) != validPaths.end(); - if (xmlOutput) { - attrs["installed"] = isInstalled ? "1" : "0"; - attrs["valid"] = isValid ? "1" : "0"; - attrs["substitutable"] = hasSubs ? "1" : "0"; - } else - columns.push_back( - (string) (isInstalled ? "I" : "-") - + (isValid ? "P" : "-") - + (hasSubs ? "S" : "-")); + try { + Path outPath = i->queryOutPath(globals.state); + bool hasSubs = substitutablePaths.find(outPath) != substitutablePaths.end(); + bool isInstalled = installed.find(outPath) != installed.end(); + bool isValid = validPaths.find(outPath) != validPaths.end(); + if (xmlOutput) { + attrs["installed"] = isInstalled ? "1" : "0"; + attrs["valid"] = isValid ? "1" : "0"; + attrs["substitutable"] = hasSubs ? "1" : "0"; + } else + columns.push_back( + (string) (isInstalled ? "I" : "-") + + (isValid ? "P" : "-") + + (hasSubs ? "S" : "-")); + } catch (ImportReadOnlyError & e) { + if (!xmlOutput) columns.push_back("?"); + } } if (xmlOutput) @@ -995,9 +1016,9 @@ static void opQuery(Globals & globals, columns.push_back(i->attrPath); if (xmlOutput) - attrs["name"] = i->name; + attrs["name"] = i->queryName(globals.state); else if (printName) - columns.push_back(i->name); + columns.push_back(i->queryName(globals.state)); if (compareVersions) { /* Compare this element against the versions of the @@ -1005,7 +1026,7 @@ static void opQuery(Globals & globals, elements, or the set of installed elements. !!! This is O(N * M), should be O(N * lg M). */ string version; - VersionDiff diff = compareVersionAgainstSet(*i, otherElems, version); + VersionDiff diff = compareVersionAgainstSet(globals.state, *i, otherElems, version); char ch; switch (diff) { @@ -1029,62 +1050,75 @@ static void opQuery(Globals & globals, } if (xmlOutput) { - if (i->system != "") attrs["system"] = i->system; + if (i->querySystem(globals.state) != "") attrs["system"] = i->querySystem(globals.state); } else if (printSystem) - columns.push_back(i->system); + columns.push_back(i->querySystem(globals.state)); if (printDrvPath) { - string drvPath = i->queryDrvPath(globals.state); - if (xmlOutput) { - if (drvPath != "") attrs["drvPath"] = drvPath; - } else - columns.push_back(drvPath == "" ? "-" : drvPath); + try { + string drvPath = i->queryDrvPath(globals.state); + if (xmlOutput) { + if (drvPath != "") attrs["drvPath"] = drvPath; + } else + columns.push_back(drvPath == "" ? "-" : drvPath); + } catch (ImportReadOnlyError & e) { + if (!xmlOutput) columns.push_back("?"); + } } if (printOutPath) { - string outPath = i->queryOutPath(globals.state); - if (xmlOutput) { - if (outPath != "") attrs["outPath"] = outPath; - } else - columns.push_back(outPath); + try { + string outPath = i->queryOutPath(globals.state); + if (xmlOutput) { + if (outPath != "") attrs["outPath"] = outPath; + } else + columns.push_back(outPath); + } catch (ImportReadOnlyError & e) { + if (!xmlOutput) columns.push_back("?"); + } } if (printDescription) { - MetaInfo meta = i->queryMetaInfo(globals.state); - MetaValue value = meta["description"]; - string descr = value.type == MetaValue::tpString ? value.stringValue : ""; - if (xmlOutput) { - if (descr != "") attrs["description"] = descr; - } else - columns.push_back(descr); + try { + MetaValue value = i->queryMetaInfo(globals.state, "description"); + string descr = value.type == MetaValue::tpString ? value.stringValue : ""; + if (xmlOutput) { + if (descr != "") attrs["description"] = descr; + } else + columns.push_back(descr); + } catch (ImportReadOnlyError & e) { + if (!xmlOutput) columns.push_back("?"); + } } if (xmlOutput) if (printMeta) { XMLOpenElement item(xml, "item", attrs); - MetaInfo meta = i->queryMetaInfo(globals.state); - for (MetaInfo::iterator j = meta.begin(); j != meta.end(); ++j) { - XMLAttrs attrs2; - attrs2["name"] = j->first; - if (j->second.type == MetaValue::tpString) { - attrs2["type"] = "string"; - attrs2["value"] = j->second.stringValue; - xml.writeEmptyElement("meta", attrs2); - } else if (j->second.type == MetaValue::tpInt) { - attrs2["type"] = "int"; - attrs2["value"] = (format("%1%") % j->second.intValue).str(); - xml.writeEmptyElement("meta", attrs2); - } else if (j->second.type == MetaValue::tpStrings) { - attrs2["type"] = "strings"; - XMLOpenElement m(xml, "meta", attrs2); - foreach (Strings::iterator, k, j->second.stringValues) { - XMLAttrs attrs3; - attrs3["value"] = *k; - xml.writeEmptyElement("string", attrs3); - } + try { + MetaInfo meta = i->queryMetaInfo(globals.state); + for (MetaInfo::iterator j = meta.begin(); j != meta.end(); ++j) { + XMLAttrs attrs2; + attrs2["name"] = j->first; + if (j->second.type == MetaValue::tpString) { + attrs2["type"] = "string"; + attrs2["value"] = j->second.stringValue; + xml.writeEmptyElement("meta", attrs2); + } else if (j->second.type == MetaValue::tpInt) { + attrs2["type"] = "int"; + attrs2["value"] = (format("%1%") % j->second.intValue).str(); + xml.writeEmptyElement("meta", attrs2); + } else if (j->second.type == MetaValue::tpStrings) { + attrs2["type"] = "strings"; + XMLOpenElement m(xml, "meta", attrs2); + foreach (Strings::iterator, k, j->second.stringValues) { + XMLAttrs attrs3; + attrs3["value"] = *k; + xml.writeEmptyElement("string", attrs3); + } + } } - } + } catch (ImportReadOnlyError & e) { } } else xml.writeEmptyElement("item", attrs); @@ -1094,7 +1128,7 @@ static void opQuery(Globals & globals, cout.flush(); } catch (AssertionError & e) { - printMsg(lvlTalkative, format("skipping derivation named `%1%' which gives an assertion failure") % i->name); + printMsg(lvlTalkative, format("skipping derivation named `%1%' which gives an assertion failure") % i->queryName(globals.state)); } } diff --git a/src/nix-env/user-env.cc b/src/nix-env/user-env.cc index 510c5ca3817..1cd82cbea7f 100644 --- a/src/nix-env/user-env.cc +++ b/src/nix-env/user-env.cc @@ -11,7 +11,7 @@ namespace nix { -static void readLegacyManifest(const Path & path, DrvInfos & elems); +static void readLegacyManifest(EvalState & state, const Path & path, DrvInfos & elems); DrvInfos queryInstalled(EvalState & state, const Path & userEnv) @@ -27,7 +27,7 @@ DrvInfos queryInstalled(EvalState & state, const Path & userEnv) Bindings bindings; getDerivations(state, v, "", bindings, elems); } else if (pathExists(oldManifestFile)) - readLegacyManifest(oldManifestFile, elems); + readLegacyManifest(state, oldManifestFile, elems); return elems; } @@ -63,8 +63,8 @@ bool createUserEnv(EvalState & state, DrvInfos & elems, state.mkAttrs(v, 8); mkString(*state.allocAttr(v, state.sType), "derivation"); - mkString(*state.allocAttr(v, state.sName), i->name); - mkString(*state.allocAttr(v, state.sSystem), i->system); + mkString(*state.allocAttr(v, state.sName), i->queryName(state)); + mkString(*state.allocAttr(v, state.sSystem), i->querySystem(state)); mkString(*state.allocAttr(v, state.sOutPath), i->queryOutPath(state)); if (drvPath != "") mkString(*state.allocAttr(v, state.sDrvPath), i->queryDrvPath(state)); @@ -214,7 +214,7 @@ static MetaInfo parseMeta(std::istream & str) } -static void readLegacyManifest(const Path & path, DrvInfos & elems) +static void readLegacyManifest(EvalState & state, const Path & path, DrvInfos & elems) { string manifest = readFile(path); std::istringstream str(manifest); @@ -234,10 +234,10 @@ static void readLegacyManifest(const Path & path, DrvInfos & elems) if (name == "meta") elem.setMetaInfo(parseMeta(str)); else { string value = parseStr(str); - if (name == "name") elem.name = value; + if (name == "name") elem.setName(value); else if (name == "outPath") elem.setOutPath(value); else if (name == "drvPath") elem.setDrvPath(value); - else if (name == "system") elem.system = value; + else if (name == "system") elem.setSystem(value); } expect(str, ",NoPos)"); @@ -245,7 +245,7 @@ static void readLegacyManifest(const Path & path, DrvInfos & elems) expect(str, ")"); - if (elem.name != "") { + if (elem.queryName(state) != "") { elem.attrPath = int2String(n++); elems.push_back(elem); }