aboutsummaryrefslogtreecommitdiff
path: root/src/nix/installables.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix/installables.cc')
-rw-r--r--src/nix/installables.cc55
1 files changed, 31 insertions, 24 deletions
diff --git a/src/nix/installables.cc b/src/nix/installables.cc
index 013218cd9..708a0dc88 100644
--- a/src/nix/installables.cc
+++ b/src/nix/installables.cc
@@ -12,26 +12,28 @@
namespace nix {
+
SourceExprCommand::SourceExprCommand()
{
- mkFlag()
- .shortName('f')
- .longName("file")
- .label("file")
- .description("evaluate FILE rather than the default")
- .dest(&file);
+ addFlag({
+ .longName = "file",
+ .shortName = 'f',
+ .description = "evaluate FILE rather than the default",
+ .labels = {"file"},
+ .handler = {&file}
+ });
}
Value * SourceExprCommand::getSourceExpr(EvalState & state)
{
- if (vSourceExpr) return vSourceExpr;
+ if (vSourceExpr) return *vSourceExpr;
auto sToplevel = state.symbols.create("_toplevel");
- vSourceExpr = state.allocValue();
+ vSourceExpr = allocRootValue(state.allocValue());
if (file != "")
- state.evalFile(lookupFileArg(state, file), *vSourceExpr);
+ state.evalFile(lookupFileArg(state, file), **vSourceExpr);
else {
@@ -39,9 +41,9 @@ Value * SourceExprCommand::getSourceExpr(EvalState & state)
auto searchPath = state.getSearchPath();
- state.mkAttrs(*vSourceExpr, 1024);
+ state.mkAttrs(**vSourceExpr, 1024);
- mkBool(*state.allocAttr(*vSourceExpr, sToplevel), true);
+ mkBool(*state.allocAttr(**vSourceExpr, sToplevel), true);
std::unordered_set<std::string> seen;
@@ -52,7 +54,7 @@ Value * SourceExprCommand::getSourceExpr(EvalState & state)
mkPrimOpApp(*v1, state.getBuiltin("findFile"), state.getBuiltin("nixPath"));
Value * v2 = state.allocValue();
mkApp(*v2, *v1, mkString(*state.allocValue(), name));
- mkApp(*state.allocAttr(*vSourceExpr, state.symbols.create(name)),
+ mkApp(*state.allocAttr(**vSourceExpr, state.symbols.create(name)),
state.getBuiltin("import"), *v2);
};
@@ -66,10 +68,10 @@ Value * SourceExprCommand::getSourceExpr(EvalState & state)
} else
addEntry(i.first);
- vSourceExpr->attrs->sort();
+ (*vSourceExpr)->attrs->sort();
}
- return vSourceExpr;
+ return *vSourceExpr;
}
ref<EvalState> SourceExprCommand::getEvalState()
@@ -100,15 +102,20 @@ struct InstallableStorePath : Installable
Buildables toBuildables() override
{
std::map<std::string, StorePath> outputs;
- outputs.insert_or_assign("out", storePath.clone());
+ outputs.insert_or_assign("out", storePath);
Buildable b{
- .drvPath = storePath.isDerivation() ? storePath.clone() : std::optional<StorePath>(),
+ .drvPath = storePath.isDerivation() ? storePath : std::optional<StorePath>(),
.outputs = std::move(outputs)
};
Buildables bs;
bs.push_back(std::move(b));
return bs;
}
+
+ std::optional<StorePath> getStorePath() override
+ {
+ return storePath;
+ }
};
struct InstallableValue : Installable
@@ -134,7 +141,7 @@ struct InstallableValue : Installable
for (auto & drv : drvs) {
Buildable b{.drvPath = state->store->parseStorePath(drv.queryDrvPath())};
- drvPaths.insert(b.drvPath->clone());
+ drvPaths.insert(*b.drvPath);
auto outputName = drv.queryOutputName();
if (outputName == "")
@@ -148,10 +155,10 @@ struct InstallableValue : Installable
// Hack to recognize .all: if all drvs have the same drvPath,
// merge the buildables.
if (drvPaths.size() == 1) {
- Buildable b{.drvPath = drvPaths.begin()->clone()};
+ Buildable b{.drvPath = *drvPaths.begin()};
for (auto & b2 : res)
for (auto & output : b2.outputs)
- b.outputs.insert_or_assign(output.first, output.second.clone());
+ b.outputs.insert_or_assign(output.first, output.second);
Buildables bs;
bs.push_back(std::move(b));
return bs;
@@ -266,7 +273,7 @@ Buildables build(ref<Store> store, RealiseMode mode,
pathsToBuild.push_back({*b.drvPath, outputNames});
} else
for (auto & output : b.outputs)
- pathsToBuild.push_back({output.second.clone()});
+ pathsToBuild.push_back({output.second});
buildables.push_back(std::move(b));
}
}
@@ -286,7 +293,7 @@ StorePathSet toStorePaths(ref<Store> store, RealiseMode mode,
for (auto & b : build(store, mode, installables))
for (auto & output : b.outputs)
- outPaths.insert(output.second.clone());
+ outPaths.insert(output.second);
return outPaths;
}
@@ -299,7 +306,7 @@ StorePath toStorePath(ref<Store> store, RealiseMode mode,
if (paths.size() != 1)
throw Error("argument '%s' should evaluate to one store path", installable->what());
- return paths.begin()->clone();
+ return *paths.begin();
}
StorePathSet toDerivations(ref<Store> store,
@@ -317,10 +324,10 @@ StorePathSet toDerivations(ref<Store> store,
if (derivers.empty())
throw Error("'%s' does not have a known deriver", i->what());
// FIXME: use all derivers?
- drvPaths.insert(derivers.begin()->clone());
+ drvPaths.insert(*derivers.begin());
}
} else
- drvPaths.insert(b.drvPath->clone());
+ drvPaths.insert(*b.drvPath);
}
return drvPaths;