1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-06 00:51:00 +01:00

Merge remote-tracking branch 'origin/master' into flakes

This commit is contained in:
Eelco Dolstra 2019-12-11 14:53:30 +01:00
commit ecb3a1afa2
119 changed files with 3905 additions and 2250 deletions

View file

@ -208,10 +208,11 @@ static long comparePriorities(EvalState & state, DrvInfo & drv1, DrvInfo & drv2)
// at a time.
static bool isPrebuilt(EvalState & state, DrvInfo & elem)
{
Path path = elem.queryOutPath();
auto path = state.store->parseStorePath(elem.queryOutPath());
if (state.store->isValidPath(path)) return true;
PathSet ps = state.store->querySubstitutablePaths({path});
return ps.find(path) != ps.end();
StorePathSet paths;
paths.insert(path.clone()); // FIXME: why doesn't StorePathSet{path.clone()} work?
return state.store->querySubstitutablePaths(paths).count(path);
}
@ -371,24 +372,21 @@ static void queryInstSources(EvalState & state,
case srcStorePaths: {
for (auto & i : args) {
Path path = state.store->followLinksToStorePath(i);
auto path = state.store->followLinksToStorePath(i);
string name = baseNameOf(path);
string::size_type dash = name.find('-');
if (dash != string::npos)
name = string(name, dash + 1);
std::string name(path.name());
DrvInfo elem(state, "", nullptr);
elem.setName(name);
if (isDerivation(path)) {
elem.setDrvPath(path);
elem.setOutPath(state.store->derivationFromPath(path).findOutput("out"));
if (path.isDerivation()) {
elem.setDrvPath(state.store->printStorePath(path));
elem.setOutPath(state.store->printStorePath(state.store->derivationFromPath(path).findOutput("out")));
if (name.size() >= drvExtension.size() &&
string(name, name.size() - drvExtension.size()) == drvExtension)
name = string(name, 0, name.size() - drvExtension.size());
}
else elem.setOutPath(path);
else elem.setOutPath(state.store->printStorePath(path));
elems.push_back(elem);
}
@ -421,13 +419,13 @@ static void queryInstSources(EvalState & state,
static void printMissing(EvalState & state, DrvInfos & elems)
{
PathSet targets;
std::vector<StorePathWithOutputs> targets;
for (auto & i : elems) {
Path drvPath = i.queryDrvPath();
if (drvPath != "")
targets.insert(drvPath);
targets.emplace_back(state.store->parseStorePath(drvPath));
else
targets.insert(i.queryOutPath());
targets.emplace_back(state.store->parseStorePath(i.queryOutPath()));
}
printMissing(state.store, targets);
@ -697,15 +695,15 @@ static void opSet(Globals & globals, Strings opFlags, Strings opArgs)
drv.setName(globals.forceName);
if (drv.queryDrvPath() != "") {
PathSet paths = {drv.queryDrvPath()};
std::vector<StorePathWithOutputs> paths{globals.state->store->parseStorePath(drv.queryDrvPath())};
printMissing(globals.state->store, paths);
if (globals.dryRun) return;
globals.state->store->buildPaths(paths, globals.state->repair ? bmRepair : bmNormal);
}
else {
printMissing(globals.state->store, {drv.queryOutPath()});
} else {
printMissing(globals.state->store,
{globals.state->store->parseStorePath(drv.queryOutPath())});
if (globals.dryRun) return;
globals.state->store->ensurePath(drv.queryOutPath());
globals.state->store->ensurePath(globals.state->store->parseStorePath(drv.queryOutPath()));
}
debug(format("switching to new user environment"));
@ -729,7 +727,7 @@ static void uninstallDerivations(Globals & globals, Strings & selectors,
for (auto & j : selectors)
/* !!! the repeated calls to followLinksToStorePath()
are expensive, should pre-compute them. */
if ((isPath(j) && i.queryOutPath() == globals.state->store->followLinksToStorePath(j))
if ((isPath(j) && globals.state->store->parseStorePath(i.queryOutPath()) == globals.state->store->followLinksToStorePath(j))
|| DrvName(j).matches(drvName))
{
printInfo("uninstalling '%s'", i.queryName());
@ -953,12 +951,13 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
/* Query which paths have substitutes. */
PathSet validPaths, substitutablePaths;
StorePathSet validPaths;
StorePathSet substitutablePaths;
if (printStatus || globals.prebuiltOnly) {
PathSet paths;
StorePathSet paths;
for (auto & i : elems)
try {
paths.insert(i.queryOutPath());
paths.insert(globals.state->store->parseStorePath(i.queryOutPath()));
} catch (AssertionError & e) {
printMsg(lvlTalkative, "skipping derivation named '%s' which gives an assertion failure", i.queryName());
i.setFailed();
@ -989,8 +988,8 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
//Activity act(*logger, lvlDebug, format("outputting query result '%1%'") % i.attrPath);
if (globals.prebuiltOnly &&
validPaths.find(i.queryOutPath()) == validPaths.end() &&
substitutablePaths.find(i.queryOutPath()) == substitutablePaths.end())
!validPaths.count(globals.state->store->parseStorePath(i.queryOutPath())) &&
!substitutablePaths.count(globals.state->store->parseStorePath(i.queryOutPath())))
continue;
/* For table output. */
@ -1001,9 +1000,9 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
if (printStatus) {
Path outPath = i.queryOutPath();
bool hasSubs = substitutablePaths.find(outPath) != substitutablePaths.end();
bool hasSubs = substitutablePaths.count(globals.state->store->parseStorePath(outPath));
bool isInstalled = installed.find(outPath) != installed.end();
bool isValid = validPaths.find(outPath) != validPaths.end();
bool isValid = validPaths.count(globals.state->store->parseStorePath(outPath));
if (xmlOutput) {
attrs["installed"] = isInstalled ? "1" : "0";
attrs["valid"] = isValid ? "1" : "0";
@ -1347,7 +1346,7 @@ static int _main(int argc, char * * argv)
using LegacyArgs::LegacyArgs;
};
MyArgs myArgs(baseNameOf(argv[0]), [&](Strings::iterator & arg, const Strings::iterator & end) {
MyArgs myArgs(std::string(baseNameOf(argv[0])), [&](Strings::iterator & arg, const Strings::iterator & end) {
Operation oldOp = op;
if (*arg == "--help")

View file

@ -32,16 +32,16 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
{
/* Build the components in the user environment, if they don't
exist already. */
PathSet drvsToBuild;
std::vector<StorePathWithOutputs> drvsToBuild;
for (auto & i : elems)
if (i.queryDrvPath() != "")
drvsToBuild.insert(i.queryDrvPath());
drvsToBuild.push_back({state.store->parseStorePath(i.queryDrvPath())});
debug(format("building user environment dependencies"));
state.store->buildPaths(drvsToBuild, state.repair ? bmRepair : bmNormal);
/* Construct the whole top level derivation. */
PathSet references;
StorePathSet references;
Value manifest;
state.mkList(manifest, elems.size());
unsigned int n = 0;
@ -77,10 +77,10 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
/* This is only necessary when installing store paths, e.g.,
`nix-env -i /nix/store/abcd...-foo'. */
state.store->addTempRoot(j.second);
state.store->ensurePath(j.second);
state.store->addTempRoot(state.store->parseStorePath(j.second));
state.store->ensurePath(state.store->parseStorePath(j.second));
references.insert(j.second);
references.insert(state.store->parseStorePath(j.second));
}
// Copy the meta attributes.
@ -95,14 +95,14 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
vMeta.attrs->sort();
v.attrs->sort();
if (drvPath != "") references.insert(drvPath);
if (drvPath != "") references.insert(state.store->parseStorePath(drvPath));
}
/* Also write a copy of the list of user environment elements to
the store; we need it for future modifications of the
environment. */
Path manifestFile = state.store->addTextToStore("env-manifest.nix",
(format("%1%") % manifest).str(), references);
auto manifestFile = state.store->addTextToStore("env-manifest.nix",
fmt("%s", manifest), references);
/* Get the environment builder expression. */
Value envBuilder;
@ -113,7 +113,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
Value args, topLevel;
state.mkAttrs(args, 3);
mkString(*state.allocAttr(args, state.symbols.create("manifest")),
manifestFile, {manifestFile});
state.store->printStorePath(manifestFile), {state.store->printStorePath(manifestFile)});
args.attrs->push_back(Attr(state.symbols.create("derivations"), &manifest));
args.attrs->sort();
mkApp(topLevel, envBuilder, args);
@ -123,13 +123,15 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
state.forceValue(topLevel);
PathSet context;
Attr & aDrvPath(*topLevel.attrs->find(state.sDrvPath));
Path topLevelDrv = state.coerceToPath(aDrvPath.pos ? *(aDrvPath.pos) : noPos, *(aDrvPath.value), context);
auto topLevelDrv = state.store->parseStorePath(state.coerceToPath(aDrvPath.pos ? *(aDrvPath.pos) : noPos, *(aDrvPath.value), context));
Attr & aOutPath(*topLevel.attrs->find(state.sOutPath));
Path topLevelOut = state.coerceToPath(aOutPath.pos ? *(aOutPath.pos) : noPos, *(aOutPath.value), context);
/* Realise the resulting store expression. */
debug("building user environment");
state.store->buildPaths({topLevelDrv}, state.repair ? bmRepair : bmNormal);
std::vector<StorePathWithOutputs> topLevelDrvs;
topLevelDrvs.push_back(StorePathWithOutputs{topLevelDrv.clone()});
state.store->buildPaths(topLevelDrvs, state.repair ? bmRepair : bmNormal);
/* Switch the current user environment to the output path. */
auto store2 = state.store.dynamic_pointer_cast<LocalFSStore>();