nix flake check: Check defaultPackage, devShell and packages

This commit is contained in:
Eelco Dolstra 2019-05-29 20:57:08 +02:00
parent e0aaf05f4f
commit 0e32b32fa3
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -262,6 +262,19 @@ struct CmdFlakeCheck : FlakeCommand, MixJSON
auto state = getEvalState(); auto state = getEvalState();
auto flake = resolveFlake(); auto flake = resolveFlake();
auto checkDerivation = [&](const std::string & attrPath, Value & v) {
try {
auto drvInfo = getDerivation(*state, v, false);
if (!drvInfo)
throw Error("flake attribute '%s' is not a derivation", attrPath);
// FIXME: check meta attributes
return drvInfo->queryDrvPath();
} catch (Error & e) {
e.addPrefix(fmt("while checking flake attribute '" ANSI_BOLD "%s" ANSI_NORMAL "':\n", attrPath));
throw;
}
};
PathSet drvPaths; PathSet drvPaths;
{ {
@ -281,20 +294,21 @@ struct CmdFlakeCheck : FlakeCommand, MixJSON
if (name == "checks") { if (name == "checks") {
state->forceAttrs(vProvide); state->forceAttrs(vProvide);
for (auto & aCheck : *vProvide.attrs) { for (auto & aCheck : *vProvide.attrs)
try { drvPaths.insert(checkDerivation(
auto drvInfo = getDerivation(*state, *aCheck.value, false); name + "." + (std::string) aCheck.name, *aCheck.value));
if (!drvInfo)
throw Error("flake output 'check.%s' is not a derivation", aCheck.name);
drvPaths.insert(drvInfo->queryDrvPath());
// FIXME: check meta attributes?
} catch (Error & e) {
e.addPrefix(fmt("while checking flake check '" ANSI_BOLD "%s" ANSI_NORMAL "':\n", aCheck.name));
throw;
}
} }
else if (name == "packages") {
state->forceAttrs(vProvide);
for (auto & aCheck : *vProvide.attrs)
checkDerivation(
name + "." + (std::string) aCheck.name, *aCheck.value);
} }
else if (name == "defaultPackage" || name == "devShell")
checkDerivation(name, vProvide);
} catch (Error & e) { } catch (Error & e) {
e.addPrefix(fmt("while checking flake output '" ANSI_BOLD "%s" ANSI_NORMAL "':\n", name)); e.addPrefix(fmt("while checking flake output '" ANSI_BOLD "%s" ANSI_NORMAL "':\n", name));
throw; throw;