Add EvalState::coerceToStorePath() helper

This is useful whenever we want to evaluate something to a store path
(e.g. in get-drvs.cc).

Extracted from the lazy-trees branch (where we can require that a
store path must come from a store source tree accessor).
This commit is contained in:
Eelco Dolstra 2022-03-02 10:57:19 +01:00
parent 3e3d0711d4
commit b55d79728c
13 changed files with 123 additions and 101 deletions

View file

@ -468,10 +468,10 @@ std::vector<InstallableValue::DerivationInfo> InstallableAttrPath::toDerivations
std::vector<DerivationInfo> res; std::vector<DerivationInfo> res;
for (auto & drvInfo : drvInfos) { for (auto & drvInfo : drvInfos) {
res.push_back({ auto drvPath = drvInfo.queryDrvPath();
state->store->parseStorePath(drvInfo.queryDrvPath()), if (!drvPath)
drvInfo.queryOutputName() throw Error("'%s' is not a derivation", what());
}); res.push_back({ *drvPath, drvInfo.queryOutputName() });
} }
return res; return res;

View file

@ -2058,6 +2058,18 @@ Path EvalState::coerceToPath(const Pos & pos, Value & v, PathSet & context)
} }
StorePath EvalState::coerceToStorePath(const Pos & pos, Value & v, PathSet & context)
{
auto path = coerceToString(pos, v, context, false, false).toOwned();
if (auto storePath = store->maybeParseStorePath(path))
return *storePath;
throw EvalError({
.msg = hintfmt("path '%1%' is not in the Nix store", path),
.errPos = pos
});
}
bool EvalState::eqValues(Value & v1, Value & v2) bool EvalState::eqValues(Value & v1, Value & v2)
{ {
forceValue(v1, noPos); forceValue(v1, noPos);

View file

@ -272,6 +272,9 @@ public:
path. Nothing is copied to the store. */ path. Nothing is copied to the store. */
Path coerceToPath(const Pos & pos, Value & v, PathSet & context); Path coerceToPath(const Pos & pos, Value & v, PathSet & context);
/* Like coerceToPath, but the result must be a store path. */
StorePath coerceToStorePath(const Pos & pos, Value & v, PathSet & context);
public: public:
/* The base environment, containing the builtin functions and /* The base environment, containing the builtin functions and

View file

@ -22,7 +22,7 @@ DrvInfo::DrvInfo(EvalState & state, ref<Store> store, const std::string & drvPat
{ {
auto [drvPath, selectedOutputs] = parsePathWithOutputs(*store, drvPathWithOutputs); auto [drvPath, selectedOutputs] = parsePathWithOutputs(*store, drvPathWithOutputs);
this->drvPath = store->printStorePath(drvPath); this->drvPath = drvPath;
auto drv = store->derivationFromPath(drvPath); auto drv = store->derivationFromPath(drvPath);
@ -41,9 +41,7 @@ DrvInfo::DrvInfo(EvalState & state, ref<Store> store, const std::string & drvPat
throw Error("derivation '%s' does not have output '%s'", store->printStorePath(drvPath), outputName); throw Error("derivation '%s' does not have output '%s'", store->printStorePath(drvPath), outputName);
auto & [outputName, output] = *i; auto & [outputName, output] = *i;
auto optStorePath = output.path(*store, drv.name, outputName); outPath = {output.path(*store, drv.name, outputName)};
if (optStorePath)
outPath = store->printStorePath(*optStorePath);
} }
@ -68,24 +66,35 @@ std::string DrvInfo::querySystem() const
} }
std::string DrvInfo::queryDrvPath() const std::optional<StorePath> DrvInfo::queryDrvPath() const
{ {
if (drvPath == "" && attrs) { if (!drvPath && attrs) {
Bindings::iterator i = attrs->find(state->sDrvPath); Bindings::iterator i = attrs->find(state->sDrvPath);
PathSet context; PathSet context;
drvPath = i != attrs->end() ? state->coerceToPath(*i->pos, *i->value, context) : ""; if (i == attrs->end())
drvPath = {std::nullopt};
else
drvPath = {state->coerceToStorePath(*i->pos, *i->value, context)};
} }
return drvPath; return drvPath.value_or(std::nullopt);
} }
std::string DrvInfo::queryOutPath() const StorePath DrvInfo::requireDrvPath() const
{
if (auto drvPath = queryDrvPath())
return *drvPath;
throw Error("derivation does not contain a 'drvPath' attribute");
}
StorePath DrvInfo::queryOutPath() const
{ {
if (!outPath && attrs) { if (!outPath && attrs) {
Bindings::iterator i = attrs->find(state->sOutPath); Bindings::iterator i = attrs->find(state->sOutPath);
PathSet context; PathSet context;
if (i != attrs->end()) if (i != attrs->end())
outPath = state->coerceToPath(*i->pos, *i->value, context); outPath = state->coerceToStorePath(*i->pos, *i->value, context);
} }
if (!outPath) if (!outPath)
throw UnimplementedError("CA derivations are not yet supported"); throw UnimplementedError("CA derivations are not yet supported");
@ -113,10 +122,10 @@ DrvInfo::Outputs DrvInfo::queryOutputs(bool onlyOutputsToInstall)
Bindings::iterator outPath = out->value->attrs->find(state->sOutPath); Bindings::iterator outPath = out->value->attrs->find(state->sOutPath);
if (outPath == out->value->attrs->end()) continue; // FIXME: throw error? if (outPath == out->value->attrs->end()) continue; // FIXME: throw error?
PathSet context; PathSet context;
outputs[name] = state->coerceToPath(*outPath->pos, *outPath->value, context); outputs.emplace(name, state->coerceToStorePath(*outPath->pos, *outPath->value, context));
} }
} else } else
outputs["out"] = queryOutPath(); outputs.emplace("out", queryOutPath());
} }
if (!onlyOutputsToInstall || !attrs) if (!onlyOutputsToInstall || !attrs)
return outputs; return outputs;

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "eval.hh" #include "eval.hh"
#include "path.hh"
#include <string> #include <string>
#include <map> #include <map>
@ -12,15 +13,15 @@ namespace nix {
struct DrvInfo struct DrvInfo
{ {
public: public:
typedef std::map<std::string, Path> Outputs; typedef std::map<std::string, StorePath> Outputs;
private: private:
EvalState * state; EvalState * state;
mutable std::string name; mutable std::string name;
mutable std::string system; mutable std::string system;
mutable std::string drvPath; mutable std::optional<std::optional<StorePath>> drvPath;
mutable std::optional<std::string> outPath; mutable std::optional<StorePath> outPath;
mutable std::string outputName; mutable std::string outputName;
Outputs outputs; Outputs outputs;
@ -41,8 +42,9 @@ public:
std::string queryName() const; std::string queryName() const;
std::string querySystem() const; std::string querySystem() const;
std::string queryDrvPath() const; std::optional<StorePath> queryDrvPath() const;
std::string queryOutPath() const; StorePath requireDrvPath() const;
StorePath queryOutPath() const;
std::string queryOutputName() const; std::string queryOutputName() const;
/** Return the list of outputs. The "outputs to install" are determined by `meta.outputsToInstall`. */ /** Return the list of outputs. The "outputs to install" are determined by `meta.outputsToInstall`. */
Outputs queryOutputs(bool onlyOutputsToInstall = false); Outputs queryOutputs(bool onlyOutputsToInstall = false);
@ -61,8 +63,8 @@ public:
*/ */
void setName(const std::string & s) { name = s; } void setName(const std::string & s) { name = s; }
void setDrvPath(const std::string & s) { drvPath = s; } void setDrvPath(StorePath path) { drvPath = {{std::move(path)}}; }
void setOutPath(const std::string & s) { outPath = s; } void setOutPath(StorePath path) { outPath = {{std::move(path)}}; }
void setFailed() { failed = true; }; void setFailed() { failed = true; };
bool hasFailed() { return failed; }; bool hasFailed() { return failed; };

View file

@ -346,7 +346,7 @@ static void main_nix_build(int argc, char * * argv)
throw UsageError("nix-shell requires a single derivation"); throw UsageError("nix-shell requires a single derivation");
auto & drvInfo = drvs.front(); auto & drvInfo = drvs.front();
auto drv = evalStore->derivationFromPath(evalStore->parseStorePath(drvInfo.queryDrvPath())); auto drv = evalStore->derivationFromPath(drvInfo.requireDrvPath());
std::vector<StorePathWithOutputs> pathsToBuild; std::vector<StorePathWithOutputs> pathsToBuild;
RealisedPath::Set pathsToCopy; RealisedPath::Set pathsToCopy;
@ -369,7 +369,7 @@ static void main_nix_build(int argc, char * * argv)
if (!drv) if (!drv)
throw Error("the 'bashInteractive' attribute in <nixpkgs> did not evaluate to a derivation"); throw Error("the 'bashInteractive' attribute in <nixpkgs> did not evaluate to a derivation");
auto bashDrv = store->parseStorePath(drv->queryDrvPath()); auto bashDrv = drv->requireDrvPath();
pathsToBuild.push_back({bashDrv}); pathsToBuild.push_back({bashDrv});
pathsToCopy.insert(bashDrv); pathsToCopy.insert(bashDrv);
shellDrv = bashDrv; shellDrv = bashDrv;
@ -458,10 +458,7 @@ static void main_nix_build(int argc, char * * argv)
} }
} }
ParsedDerivation parsedDrv( ParsedDerivation parsedDrv(drvInfo.requireDrvPath(), drv);
StorePath(store->parseStorePath(drvInfo.queryDrvPath())),
drv
);
if (auto structAttrs = parsedDrv.prepareStructuredAttrs(*store, inputs)) { if (auto structAttrs = parsedDrv.prepareStructuredAttrs(*store, inputs)) {
auto json = structAttrs.value(); auto json = structAttrs.value();
@ -553,7 +550,7 @@ static void main_nix_build(int argc, char * * argv)
std::map<StorePath, std::pair<size_t, StringSet>> drvMap; std::map<StorePath, std::pair<size_t, StringSet>> drvMap;
for (auto & drvInfo : drvs) { for (auto & drvInfo : drvs) {
auto drvPath = store->parseStorePath(drvInfo.queryDrvPath()); auto drvPath = drvInfo.requireDrvPath();
auto outputName = drvInfo.queryOutputName(); auto outputName = drvInfo.queryOutputName();
if (outputName == "") if (outputName == "")

View file

@ -211,7 +211,7 @@ static long comparePriorities(EvalState & state, DrvInfo & drv1, DrvInfo & drv2)
// at a time. // at a time.
static bool isPrebuilt(EvalState & state, DrvInfo & elem) static bool isPrebuilt(EvalState & state, DrvInfo & elem)
{ {
auto path = state.store->parseStorePath(elem.queryOutPath()); auto path = elem.queryOutPath();
if (state.store->isValidPath(path)) return true; if (state.store->isValidPath(path)) return true;
return state.store->querySubstitutablePaths({path}).count(path); return state.store->querySubstitutablePaths({path}).count(path);
} }
@ -429,14 +429,15 @@ static void queryInstSources(EvalState & state,
elem.setName(name); elem.setName(name);
if (path.isDerivation()) { if (path.isDerivation()) {
elem.setDrvPath(state.store->printStorePath(path)); elem.setDrvPath(path);
auto outputs = state.store->queryDerivationOutputMap(path); auto outputs = state.store->queryDerivationOutputMap(path);
elem.setOutPath(state.store->printStorePath(outputs.at("out"))); elem.setOutPath(outputs.at("out"));
if (name.size() >= drvExtension.size() && if (name.size() >= drvExtension.size() &&
std::string(name, name.size() - drvExtension.size()) == drvExtension) std::string(name, name.size() - drvExtension.size()) == drvExtension)
name = name.substr(0, name.size() - drvExtension.size()); name = name.substr(0, name.size() - drvExtension.size());
} }
else elem.setOutPath(state.store->printStorePath(path)); else
elem.setOutPath(path);
elems.push_back(elem); elems.push_back(elem);
} }
@ -470,13 +471,11 @@ static void queryInstSources(EvalState & state,
static void printMissing(EvalState & state, DrvInfos & elems) static void printMissing(EvalState & state, DrvInfos & elems)
{ {
std::vector<DerivedPath> targets; std::vector<DerivedPath> targets;
for (auto & i : elems) { for (auto & i : elems)
Path drvPath = i.queryDrvPath(); if (auto drvPath = i.queryDrvPath())
if (drvPath != "") targets.push_back(DerivedPath::Built{*drvPath});
targets.push_back(DerivedPath::Built{state.store->parseStorePath(drvPath)});
else else
targets.push_back(DerivedPath::Opaque{state.store->parseStorePath(i.queryOutPath())}); targets.push_back(DerivedPath::Opaque{i.queryOutPath()});
}
printMissing(state.store, targets); printMissing(state.store, targets);
} }
@ -744,14 +743,11 @@ static void opSet(Globals & globals, Strings opFlags, Strings opArgs)
if (globals.forceName != "") if (globals.forceName != "")
drv.setName(globals.forceName); drv.setName(globals.forceName);
auto drvPath = drv.queryDrvPath();
std::vector<DerivedPath> paths { std::vector<DerivedPath> paths {
(drv.queryDrvPath() != "") drvPath
? (DerivedPath) (DerivedPath::Built { ? (DerivedPath) (DerivedPath::Built { *drvPath })
globals.state->store->parseStorePath(drv.queryDrvPath()) : (DerivedPath) (DerivedPath::Opaque { drv.queryOutPath() }),
})
: (DerivedPath) (DerivedPath::Opaque {
globals.state->store->parseStorePath(drv.queryOutPath())
}),
}; };
printMissing(globals.state->store, paths); printMissing(globals.state->store, paths);
if (globals.dryRun) return; if (globals.dryRun) return;
@ -759,8 +755,9 @@ static void opSet(Globals & globals, Strings opFlags, Strings opArgs)
debug(format("switching to new user environment")); debug(format("switching to new user environment"));
Path generation = createGeneration( Path generation = createGeneration(
ref<LocalFSStore>(store2), globals.profile, ref<LocalFSStore>(store2),
store2->parseStorePath(drv.queryOutPath())); globals.profile,
drv.queryOutPath());
switchLink(globals.profile, generation); switchLink(globals.profile, generation);
} }
@ -780,7 +777,7 @@ static void uninstallDerivations(Globals & globals, Strings & selectors,
split = std::partition( split = std::partition(
workingElems.begin(), workingElems.end(), workingElems.begin(), workingElems.end(),
[&selectorStorePath, globals](auto &elem) { [&selectorStorePath, globals](auto &elem) {
return selectorStorePath != globals.state->store->parseStorePath(elem.queryOutPath()); return selectorStorePath != elem.queryOutPath();
} }
); );
} else { } else {
@ -925,9 +922,8 @@ static void queryJSON(Globals & globals, std::vector<DrvInfo> & elems, bool prin
if (printOutPath) { if (printOutPath) {
DrvInfo::Outputs outputs = i.queryOutputs(); DrvInfo::Outputs outputs = i.queryOutputs();
JSONObject outputObj = pkgObj.object("outputs"); JSONObject outputObj = pkgObj.object("outputs");
for (auto & j : outputs) { for (auto & j : outputs)
outputObj.attr(j.first, j.second); outputObj.attr(j.first, globals.state->store->printStorePath(j.second));
}
} }
if (printMeta) { if (printMeta) {
@ -957,6 +953,8 @@ static void queryJSON(Globals & globals, std::vector<DrvInfo> & elems, bool prin
static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
{ {
auto & store(*globals.state->store);
Strings remaining; Strings remaining;
std::string attrPath; std::string attrPath;
@ -1027,12 +1025,11 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
/* We only need to know the installed paths when we are querying /* We only need to know the installed paths when we are querying
the status of the derivation. */ the status of the derivation. */
PathSet installed; /* installed paths */ StorePathSet installed; /* installed paths */
if (printStatus) { if (printStatus)
for (auto & i : installedElems) for (auto & i : installedElems)
installed.insert(i.queryOutPath()); installed.insert(i.queryOutPath());
}
/* Query which paths have substitutes. */ /* Query which paths have substitutes. */
@ -1042,13 +1039,13 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
StorePathSet paths; StorePathSet paths;
for (auto & i : elems) for (auto & i : elems)
try { try {
paths.insert(globals.state->store->parseStorePath(i.queryOutPath())); paths.insert(i.queryOutPath());
} catch (AssertionError & e) { } catch (AssertionError & e) {
printMsg(lvlTalkative, "skipping derivation named '%s' which gives an assertion failure", i.queryName()); printMsg(lvlTalkative, "skipping derivation named '%s' which gives an assertion failure", i.queryName());
i.setFailed(); i.setFailed();
} }
validPaths = globals.state->store->queryValidPaths(paths); validPaths = store.queryValidPaths(paths);
substitutablePaths = globals.state->store->querySubstitutablePaths(paths); substitutablePaths = store.querySubstitutablePaths(paths);
} }
@ -1073,8 +1070,8 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
//Activity act(*logger, lvlDebug, format("outputting query result '%1%'") % i.attrPath); //Activity act(*logger, lvlDebug, format("outputting query result '%1%'") % i.attrPath);
if (globals.prebuiltOnly && if (globals.prebuiltOnly &&
!validPaths.count(globals.state->store->parseStorePath(i.queryOutPath())) && !validPaths.count(i.queryOutPath()) &&
!substitutablePaths.count(globals.state->store->parseStorePath(i.queryOutPath()))) !substitutablePaths.count(i.queryOutPath()))
continue; continue;
/* For table output. */ /* For table output. */
@ -1084,10 +1081,10 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
XMLAttrs attrs; XMLAttrs attrs;
if (printStatus) { if (printStatus) {
Path outPath = i.queryOutPath(); auto outPath = i.queryOutPath();
bool hasSubs = substitutablePaths.count(globals.state->store->parseStorePath(outPath)); bool hasSubs = substitutablePaths.count(outPath);
bool isInstalled = installed.find(outPath) != installed.end(); bool isInstalled = installed.count(outPath);
bool isValid = validPaths.count(globals.state->store->parseStorePath(outPath)); bool isValid = validPaths.count(outPath);
if (xmlOutput) { if (xmlOutput) {
attrs["installed"] = isInstalled ? "1" : "0"; attrs["installed"] = isInstalled ? "1" : "0";
attrs["valid"] = isValid ? "1" : "0"; attrs["valid"] = isValid ? "1" : "0";
@ -1152,9 +1149,9 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
if (printDrvPath) { if (printDrvPath) {
auto drvPath = i.queryDrvPath(); auto drvPath = i.queryDrvPath();
if (xmlOutput) { if (xmlOutput) {
if (drvPath != "") attrs["drvPath"] = drvPath; if (drvPath) attrs["drvPath"] = store.printStorePath(*drvPath);
} else } else
columns.push_back(drvPath == "" ? "-" : drvPath); columns.push_back(drvPath ? store.printStorePath(*drvPath) : "-");
} }
if (printOutPath && !xmlOutput) { if (printOutPath && !xmlOutput) {
@ -1163,7 +1160,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
for (auto & j : outputs) { for (auto & j : outputs) {
if (!s.empty()) s += ';'; if (!s.empty()) s += ';';
if (j.first != "out") { s += j.first; s += "="; } if (j.first != "out") { s += j.first; s += "="; }
s += j.second; s += store.printStorePath(j.second);
} }
columns.push_back(s); columns.push_back(s);
} }
@ -1184,7 +1181,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
for (auto & j : outputs) { for (auto & j : outputs) {
XMLAttrs attrs2; XMLAttrs attrs2;
attrs2["name"] = j.first; attrs2["name"] = j.first;
attrs2["path"] = j.second; attrs2["path"] = store.printStorePath(j.second);
xml.writeEmptyElement("output", attrs2); xml.writeEmptyElement("output", attrs2);
} }
} }

View file

@ -38,8 +38,8 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
exist already. */ exist already. */
std::vector<StorePathWithOutputs> drvsToBuild; std::vector<StorePathWithOutputs> drvsToBuild;
for (auto & i : elems) for (auto & i : elems)
if (i.queryDrvPath() != "") if (auto drvPath = i.queryDrvPath())
drvsToBuild.push_back({state.store->parseStorePath(i.queryDrvPath())}); drvsToBuild.push_back({*drvPath});
debug(format("building user environment dependencies")); debug(format("building user environment dependencies"));
state.store->buildPaths( state.store->buildPaths(
@ -55,7 +55,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
/* Create a pseudo-derivation containing the name, system, /* Create a pseudo-derivation containing the name, system,
output paths, and optionally the derivation path, as well output paths, and optionally the derivation path, as well
as the meta attributes. */ as the meta attributes. */
Path drvPath = keepDerivations ? i.queryDrvPath() : ""; std::optional<StorePath> drvPath = keepDerivations ? i.queryDrvPath() : std::nullopt;
DrvInfo::Outputs outputs = i.queryOutputs(true); DrvInfo::Outputs outputs = i.queryOutputs(true);
StringSet metaNames = i.queryMetaNames(); StringSet metaNames = i.queryMetaNames();
@ -66,9 +66,9 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
auto system = i.querySystem(); auto system = i.querySystem();
if (!system.empty()) if (!system.empty())
attrs.alloc(state.sSystem).mkString(system); attrs.alloc(state.sSystem).mkString(system);
attrs.alloc(state.sOutPath).mkString(i.queryOutPath()); attrs.alloc(state.sOutPath).mkString(state.store->printStorePath(i.queryOutPath()));
if (drvPath != "") if (drvPath)
attrs.alloc(state.sDrvPath).mkString(i.queryDrvPath()); attrs.alloc(state.sDrvPath).mkString(state.store->printStorePath(*drvPath));
// Copy each output meant for installation. // Copy each output meant for installation.
auto & vOutputs = attrs.alloc(state.sOutputs); auto & vOutputs = attrs.alloc(state.sOutputs);
@ -76,15 +76,15 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
for (const auto & [m, j] : enumerate(outputs)) { for (const auto & [m, j] : enumerate(outputs)) {
(vOutputs.listElems()[m] = state.allocValue())->mkString(j.first); (vOutputs.listElems()[m] = state.allocValue())->mkString(j.first);
auto outputAttrs = state.buildBindings(2); auto outputAttrs = state.buildBindings(2);
outputAttrs.alloc(state.sOutPath).mkString(j.second); outputAttrs.alloc(state.sOutPath).mkString(state.store->printStorePath(j.second));
attrs.alloc(j.first).mkAttrs(outputAttrs); attrs.alloc(j.first).mkAttrs(outputAttrs);
/* This is only necessary when installing store paths, e.g., /* This is only necessary when installing store paths, e.g.,
`nix-env -i /nix/store/abcd...-foo'. */ `nix-env -i /nix/store/abcd...-foo'. */
state.store->addTempRoot(state.store->parseStorePath(j.second)); state.store->addTempRoot(j.second);
state.store->ensurePath(state.store->parseStorePath(j.second)); state.store->ensurePath(j.second);
references.insert(state.store->parseStorePath(j.second)); references.insert(j.second);
} }
// Copy the meta attributes. // Copy the meta attributes.
@ -99,7 +99,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
(manifest.listElems()[n++] = state.allocValue())->mkAttrs(attrs); (manifest.listElems()[n++] = state.allocValue())->mkAttrs(attrs);
if (drvPath != "") references.insert(state.store->parseStorePath(drvPath)); if (drvPath) references.insert(*drvPath);
} }
/* Also write a copy of the list of user environment elements to /* Also write a copy of the list of user environment elements to
@ -132,9 +132,9 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
state.forceValue(topLevel, [&]() { return topLevel.determinePos(noPos); }); state.forceValue(topLevel, [&]() { return topLevel.determinePos(noPos); });
PathSet context; PathSet context;
Attr & aDrvPath(*topLevel.attrs->find(state.sDrvPath)); Attr & aDrvPath(*topLevel.attrs->find(state.sDrvPath));
auto topLevelDrv = state.store->parseStorePath(state.coerceToPath(*aDrvPath.pos, *aDrvPath.value, context)); auto topLevelDrv = state.coerceToStorePath(*aDrvPath.pos, *aDrvPath.value, context);
Attr & aOutPath(*topLevel.attrs->find(state.sOutPath)); Attr & aOutPath(*topLevel.attrs->find(state.sOutPath));
Path topLevelOut = state.coerceToPath(*aOutPath.pos, *aOutPath.value, context); auto topLevelOut = state.coerceToStorePath(*aOutPath.pos, *aOutPath.value, context);
/* Realise the resulting store expression. */ /* Realise the resulting store expression. */
debug("building user environment"); debug("building user environment");
@ -158,8 +158,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
} }
debug(format("switching to new user environment")); debug(format("switching to new user environment"));
Path generation = createGeneration(ref<LocalFSStore>(store2), profile, Path generation = createGeneration(ref<LocalFSStore>(store2), profile, topLevelOut);
store2->parseStorePath(topLevelOut));
switchLink(profile, generation); switchLink(profile, generation);
} }

View file

@ -61,12 +61,13 @@ void processExpr(EvalState & state, const Strings & attrPaths,
DrvInfos drvs; DrvInfos drvs;
getDerivations(state, v, "", autoArgs, drvs, false); getDerivations(state, v, "", autoArgs, drvs, false);
for (auto & i : drvs) { for (auto & i : drvs) {
Path drvPath = i.queryDrvPath(); auto drvPath = i.requireDrvPath();
auto drvPathS = state.store->printStorePath(drvPath);
/* What output do we want? */ /* What output do we want? */
std::string outputName = i.queryOutputName(); std::string outputName = i.queryOutputName();
if (outputName == "") if (outputName == "")
throw Error("derivation '%1%' lacks an 'outputName' attribute ", drvPath); throw Error("derivation '%1%' lacks an 'outputName' attribute", drvPathS);
if (gcRoot == "") if (gcRoot == "")
printGCWarning(); printGCWarning();
@ -75,9 +76,9 @@ void processExpr(EvalState & state, const Strings & attrPaths,
if (++rootNr > 1) rootName += "-" + std::to_string(rootNr); if (++rootNr > 1) rootName += "-" + std::to_string(rootNr);
auto store2 = state.store.dynamic_pointer_cast<LocalFSStore>(); auto store2 = state.store.dynamic_pointer_cast<LocalFSStore>();
if (store2) if (store2)
drvPath = store2->addPermRoot(store2->parseStorePath(drvPath), rootName); drvPathS = store2->addPermRoot(drvPath, rootName);
} }
std::cout << fmt("%s%s\n", drvPath, (outputName != "out" ? "!" + outputName : "")); std::cout << fmt("%s%s\n", drvPathS, (outputName != "out" ? "!" + outputName : ""));
} }
} }
} }

View file

@ -97,13 +97,13 @@ struct CmdBundle : InstallableCommand
throw Error("the bundler '%s' does not produce a derivation", bundler.what()); throw Error("the bundler '%s' does not produce a derivation", bundler.what());
PathSet context2; PathSet context2;
StorePath drvPath = store->parseStorePath(evalState->coerceToPath(*attr1->pos, *attr1->value, context2)); auto drvPath = evalState->coerceToStorePath(*attr1->pos, *attr1->value, context2);
auto attr2 = vRes->attrs->get(evalState->sOutPath); auto attr2 = vRes->attrs->get(evalState->sOutPath);
if (!attr2) if (!attr2)
throw Error("the bundler '%s' does not produce a derivation", bundler.what()); throw Error("the bundler '%s' does not produce a derivation", bundler.what());
StorePath outPath = store->parseStorePath(evalState->coerceToPath(*attr2->pos, *attr2->value, context2)); auto outPath = evalState->coerceToStorePath(*attr2->pos, *attr2->value, context2);
store->buildPaths({ DerivedPath::Built { drvPath } }); store->buildPaths({ DerivedPath::Built { drvPath } });

View file

@ -327,7 +327,7 @@ struct CmdFlakeCheck : FlakeCommand
if (!drvInfo) if (!drvInfo)
throw Error("flake attribute '%s' is not a derivation", attrPath); throw Error("flake attribute '%s' is not a derivation", attrPath);
// FIXME: check meta attributes // FIXME: check meta attributes
return std::make_optional(store->parseStorePath(drvInfo->queryDrvPath())); return drvInfo->queryDrvPath();
} catch (Error & e) { } catch (Error & e) {
e.addTrace(pos, hintfmt("while checking the derivation '%s'", attrPath)); e.addTrace(pos, hintfmt("while checking the derivation '%s'", attrPath));
reportError(e); reportError(e);

View file

@ -126,7 +126,7 @@ struct ProfileManifest
for (auto & drvInfo : drvInfos) { for (auto & drvInfo : drvInfos) {
ProfileElement element; ProfileElement element;
element.storePaths = {state.store->parseStorePath(drvInfo.queryOutPath())}; element.storePaths = {drvInfo.queryOutPath()};
elements.emplace_back(std::move(element)); elements.emplace_back(std::move(element));
} }
} }

View file

@ -384,13 +384,12 @@ StorePath NixRepl::getDerivationPath(Value & v) {
auto drvInfo = getDerivation(*state, v, false); auto drvInfo = getDerivation(*state, v, false);
if (!drvInfo) if (!drvInfo)
throw Error("expression does not evaluate to a derivation, so I can't build it"); throw Error("expression does not evaluate to a derivation, so I can't build it");
Path drvPathRaw = drvInfo->queryDrvPath(); auto drvPath = drvInfo->queryDrvPath();
if (drvPathRaw == "") if (!drvPath)
throw Error("expression did not evaluate to a valid derivation (no drv path)"); throw Error("expression did not evaluate to a valid derivation (no 'drvPath' attribute)");
StorePath drvPath = state->store->parseStorePath(drvPathRaw); if (!state->store->isValidPath(*drvPath))
if (!state->store->isValidPath(drvPath)) throw Error("expression evaluated to invalid derivation '%s'", state->store->printStorePath(*drvPath));
throw Error("expression did not evaluate to a valid derivation (invalid drv path)"); return *drvPath;
return drvPath;
} }
@ -780,8 +779,11 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
str << "«derivation "; str << "«derivation ";
Bindings::iterator i = v.attrs->find(state->sDrvPath); Bindings::iterator i = v.attrs->find(state->sDrvPath);
PathSet context; PathSet context;
Path drvPath = i != v.attrs->end() ? state->coerceToPath(*i->pos, *i->value, context) : "???"; if (i != v.attrs->end())
str << drvPath << "»"; str << state->store->printStorePath(state->coerceToStorePath(*i->pos, *i->value, context));
else
str << "???";
str << "»";
} }
else if (maxDepth > 0) { else if (maxDepth > 0) {