Skip to content

Commit

Permalink
Log what nix flake check does
Browse files Browse the repository at this point in the history
There's still room for improvement, but this produces much more
informative output with `-v`:

```
$ nix flake check -v
evaluating flake...
checking flake output 'checks'...
checking derivation checks.aarch64-darwin.ghcid-ng-tests...
checking derivation checks.aarch64-darwin.ghcid-ng-clippy...
checking derivation checks.aarch64-darwin.ghcid-ng-doc...
checking derivation checks.aarch64-darwin.ghcid-ng-fmt...
checking derivation checks.aarch64-darwin.ghcid-ng-audit...
checking flake output 'packages'...
checking derivation packages.aarch64-darwin.ghcid-ng...
checking derivation packages.aarch64-darwin.ghcid-ng-tests...
checking derivation packages.aarch64-darwin.default...
checking flake output 'apps'...
checking flake output 'devShells'...
checking derivation devShells.aarch64-darwin.default...
running flake checks...
warning: The check omitted these incompatible systems: aarch64-linux, x86_64-darwin, x86_64-linux
Use '--all-systems' to check all.
```
  • Loading branch information
9999years committed Jan 20, 2024
1 parent 9b896bf commit 4922149
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/nix/flake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ struct CmdFlakeCheck : FlakeCommand

auto checkDerivation = [&](const std::string & attrPath, Value & v, const PosIdx pos) -> std::optional<StorePath> {
try {
Activity act(*logger, lvlInfo, actUnknown,
fmt("checking derivation %s", attrPath));
auto packageInfo = getDerivation(*state, v, false);
if (!packageInfo)
throw Error("flake attribute '%s' is not a derivation", attrPath);
Expand Down Expand Up @@ -427,6 +429,8 @@ struct CmdFlakeCheck : FlakeCommand

auto checkOverlay = [&](const std::string & attrPath, Value & v, const PosIdx pos) {
try {
Activity act(*logger, lvlInfo, actUnknown,
fmt("checking overlay %s", attrPath));
state->forceValue(v, pos);
if (!v.isLambda()) {
throw Error("overlay is not a function, but %s instead", showType(v));
Expand All @@ -449,6 +453,8 @@ struct CmdFlakeCheck : FlakeCommand

auto checkModule = [&](const std::string & attrPath, Value & v, const PosIdx pos) {
try {
Activity act(*logger, lvlInfo, actUnknown,
fmt("checking NixOS module %s", attrPath));
state->forceValue(v, pos);
} catch (Error & e) {
e.addTrace(resolve(pos), hintfmt("while checking the NixOS module '%s'", attrPath));
Expand All @@ -460,6 +466,8 @@ struct CmdFlakeCheck : FlakeCommand

checkHydraJobs = [&](const std::string & attrPath, Value & v, const PosIdx pos) {
try {
Activity act(*logger, lvlInfo, actUnknown,
fmt("checking Hydra job %s", attrPath));
state->forceAttrs(v, pos, "");

if (state->isDerivation(v))
Expand All @@ -469,7 +477,7 @@ struct CmdFlakeCheck : FlakeCommand
state->forceAttrs(*attr.value, attr.pos, "");
auto attrPath2 = concatStrings(attrPath, ".", state->symbols[attr.name]);
if (state->isDerivation(*attr.value)) {
Activity act(*logger, lvlChatty, actUnknown,
Activity act(*logger, lvlInfo, actUnknown,
fmt("checking Hydra job '%s'", attrPath2));
checkDerivation(attrPath2, *attr.value, attr.pos);
} else
Expand All @@ -484,7 +492,7 @@ struct CmdFlakeCheck : FlakeCommand

auto checkNixOSConfiguration = [&](const std::string & attrPath, Value & v, const PosIdx pos) {
try {
Activity act(*logger, lvlChatty, actUnknown,
Activity act(*logger, lvlInfo, actUnknown,
fmt("checking NixOS configuration '%s'", attrPath));
Bindings & bindings(*state->allocBindings(0));
auto vToplevel = findAlongAttrPath(*state, "config.system.build.toplevel", bindings, v).first;
Expand All @@ -499,7 +507,7 @@ struct CmdFlakeCheck : FlakeCommand

auto checkTemplate = [&](const std::string & attrPath, Value & v, const PosIdx pos) {
try {
Activity act(*logger, lvlChatty, actUnknown,
Activity act(*logger, lvlInfo, actUnknown,
fmt("checking template '%s'", attrPath));

state->forceAttrs(v, pos, "");
Expand Down Expand Up @@ -533,6 +541,8 @@ struct CmdFlakeCheck : FlakeCommand

auto checkBundler = [&](const std::string & attrPath, Value & v, const PosIdx pos) {
try {
Activity act(*logger, lvlInfo, actUnknown,
fmt("checking bundler %s", attrPath));
state->forceValue(v, pos);
if (!v.isLambda())
throw Error("bundler must be a function");
Expand All @@ -552,7 +562,7 @@ struct CmdFlakeCheck : FlakeCommand
enumerateOutputs(*state,
*vFlake,
[&](const std::string & name, Value & vOutput, const PosIdx pos) {
Activity act(*logger, lvlChatty, actUnknown,
Activity act(*logger, lvlInfo, actUnknown,
fmt("checking flake output '%s'", name));

try {
Expand Down

0 comments on commit 4922149

Please sign in to comment.