1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-20 01:09:37 +01:00

Support modules in toDerivation() and toApp()

This commit is contained in:
Eelco Dolstra 2020-09-03 13:11:22 +02:00
parent 22b8e07f09
commit b7d263b79a
2 changed files with 44 additions and 17 deletions

View file

@ -28,19 +28,30 @@ App Installable::toApp(EvalState & state)
}; };
} }
else if (type == "derivation") { auto getDerivation = [&](std::shared_ptr<eval_cache::AttrCursor> attr)
auto drvPath = cursor->forceDerivation(); {
auto outPath = cursor->getAttr(state.sOutPath)->getString(); auto drvPath = attr->forceDerivation();
auto outputName = cursor->getAttr(state.sOutputName)->getString(); auto outPath = attr->getAttr(state.sOutPath)->getString();
auto name = cursor->getAttr(state.sName)->getString(); auto outputName = attr->getAttr(state.sOutputName)->getString();
auto name = attr->getAttr(state.sName)->getString();
return App { return App {
.context = { { drvPath, {outputName} } }, .context = { { drvPath, {outputName} } },
.program = outPath + "/bin/" + DrvName(name).name, .program = outPath + "/bin/" + DrvName(name).name,
}; };
};
if (type == "derivation")
return getDerivation(cursor);
if (type == "module") {
// FIXME: define an 'app' option.
auto aDerivation = cursor->findAlongAttrPath(
{state.symbols.create("final"), state.symbols.create("derivation")});
if (aDerivation)
return getDerivation(aDerivation);
} }
else throw Error("attribute '%s' has unsupported type '%s'", attrPath, type);
throw Error("attribute '%s' has unsupported type '%s'", attrPath, type);
} }
} }

View file

@ -149,7 +149,8 @@ Strings SourceExprCommand::getDefaultFlakeAttrPathPrefixes()
"packages." + settings.thisSystem.get() + ".", "packages." + settings.thisSystem.get() + ".",
// As a temporary hack until Nixpkgs is properly converted // As a temporary hack until Nixpkgs is properly converted
// to provide a clean 'packages' set, look in 'legacyPackages'. // to provide a clean 'packages' set, look in 'legacyPackages'.
"legacyPackages." + settings.thisSystem.get() + "." "legacyPackages." + settings.thisSystem.get() + ".",
"modules.",
}; };
} }
@ -464,21 +465,36 @@ std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> InstallableF
auto root = cache->getRoot(); auto root = cache->getRoot();
for (auto & attrPath : getActualAttrPaths()) { for (auto & attrPath : getActualAttrPaths()) {
auto getDerivation = [&](std::shared_ptr<eval_cache::AttrCursor> attr) -> std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo>
{
auto drvPath = attr->forceDerivation();
auto drvInfo = DerivationInfo{
std::move(drvPath),
state->store->parseStorePath(attr->getAttr(state->sOutPath)->getString()),
attr->getAttr(state->sOutputName)->getString()
};
return {attrPath, lockedFlake->flake.lockedRef, std::move(drvInfo)};
};
auto attr = root->findAlongAttrPath(parseAttrPath(*state, attrPath)); auto attr = root->findAlongAttrPath(parseAttrPath(*state, attrPath));
if (!attr) continue; if (!attr) continue;
if (!attr->isDerivation()) auto aType = attr->maybeGetAttr(state->sType);
throw Error("flake output attribute '%s' is not a derivation", attrPath);
auto drvPath = attr->forceDerivation(); if (aType && aType->getString() == "derivation")
return getDerivation(attr);
auto drvInfo = DerivationInfo{ else if (aType && aType->getString() == "module") {
std::move(drvPath), if (auto aDerivation = attr->findAlongAttrPath(
state->store->parseStorePath(attr->getAttr(state->sOutPath)->getString()), {state->symbols.create("final"), state->symbols.create("derivation")}))
attr->getAttr(state->sOutputName)->getString() if (aDerivation)
}; return getDerivation(aDerivation);
}
return {attrPath, lockedFlake->flake.lockedRef, std::move(drvInfo)}; throw Error("flake output attribute '%s' is not a derivation", attrPath);
} }
throw Error("flake '%s' does not provide attribute %s", throw Error("flake '%s' does not provide attribute %s",