@@ -786,8 +786,32 @@ struct CmdFlakeCheck : FlakeCommand
786786 }
787787
788788 if (build && !drvPaths.empty ()) {
789- Activity act (*logger, lvlInfo, actUnknown, fmt (" running %d flake checks" , drvPaths.size ()));
790- store->buildPaths (drvPaths);
789+ // TODO: This filtering of substitutable paths is a temporary workaround until
790+ // https://github.com/NixOS/nix/issues/5025 (union stores) is implemented.
791+ //
792+ // Once union stores are available, this code should be replaced with a proper
793+ // union store configuration. Ideally, we'd use a union of multiple destination
794+ // stores to preserve the current behavior where different substituters can
795+ // cache different check results.
796+ //
797+ // For now, we skip building derivations whose outputs are already available
798+ // via substitution, as `nix flake check` only needs to verify buildability,
799+ // not actually produce the outputs.
800+ auto missing = store->queryMissing (drvPaths);
801+ // Only occurs if `drvPaths` contains a `DerivedPath::Opaque`, which should never happen
802+ assert (missing.unknown .empty ());
803+
804+ std::vector<DerivedPath> toBuild;
805+ for (auto & path : missing.willBuild ) {
806+ toBuild.emplace_back (
807+ DerivedPath::Built{
808+ .drvPath = makeConstantStorePathRef (path),
809+ .outputs = OutputsSpec::All{},
810+ });
811+ }
812+
813+ Activity act (*logger, lvlInfo, actUnknown, fmt (" running %d flake checks" , toBuild.size ()));
814+ store->buildPaths (toBuild);
791815 }
792816 if (hasErrors)
793817 throw Error (" some errors were encountered during the evaluation" );
0 commit comments