nix flake check: Validate nixosConfigurations outputs

This commit is contained in:
Eelco Dolstra 2019-09-19 20:15:42 +02:00
parent aeb7148afd
commit 5573365dff
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -8,6 +8,7 @@
#include "get-drvs.hh" #include "get-drvs.hh"
#include "store-api.hh" #include "store-api.hh"
#include "derivations.hh" #include "derivations.hh"
#include "attr-path.hh"
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <queue> #include <queue>
@ -341,6 +342,21 @@ struct CmdFlakeCheck : FlakeCommand, MixJSON
} }
}; };
auto checkNixOSConfiguration = [&](const std::string & attrPath, Value & v, const Pos & pos) {
try {
Activity act(*logger, lvlChatty, actUnknown,
fmt("checking NixOS configuration '%s'", attrPath));
Bindings & bindings(*state->allocBindings(0));
auto vToplevel = findAlongAttrPath(*state, "config.system.build.toplevel", bindings, v);
state->forceAttrs(*vToplevel, pos);
if (!state->isDerivation(*vToplevel))
throw Error("attribute 'config.system.build.toplevel' is not a derivation");
} catch (Error & e) {
e.addPrefix(fmt("while checking the NixOS configuration '" ANSI_BOLD "%s" ANSI_NORMAL "' at %s:\n", attrPath, pos));
throw;
}
};
{ {
Activity act(*logger, lvlInfo, actUnknown, "evaluating flake"); Activity act(*logger, lvlInfo, actUnknown, "evaluating flake");
@ -407,6 +423,13 @@ struct CmdFlakeCheck : FlakeCommand, MixJSON
*attr.value, *attr.pos); *attr.value, *attr.pos);
} }
else if (name == "nixosConfigurations") {
state->forceAttrs(vOutput, pos);
for (auto & attr : *vOutput.attrs)
checkNixOSConfiguration(name + "." + (std::string) attr.name,
*attr.value, *attr.pos);
}
else if (name == "hydraJobs") else if (name == "hydraJobs")
checkHydraJobs(name, vOutput, pos); checkHydraJobs(name, vOutput, pos);