aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-09-19 20:15:42 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-09-19 20:15:42 +0200
commit5573365dffc96df5fcb6898077aeff1cd5e2b711 (patch)
treee4ecdb8c82374c6ac32b5456f9d8d7146972d5c0 /src/nix
parentaeb7148afd56b228604b79373a45793d36d660a3 (diff)
nix flake check: Validate nixosConfigurations outputs
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/flake.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/nix/flake.cc b/src/nix/flake.cc
index 599bf12eb..2e352306e 100644
--- a/src/nix/flake.cc
+++ b/src/nix/flake.cc
@@ -8,6 +8,7 @@
#include "get-drvs.hh"
#include "store-api.hh"
#include "derivations.hh"
+#include "attr-path.hh"
#include <nlohmann/json.hpp>
#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");
@@ -407,6 +423,13 @@ struct CmdFlakeCheck : FlakeCommand, MixJSON
*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")
checkHydraJobs(name, vOutput, pos);