1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-02 23:20:59 +01:00

nix flake check: Skip substitutable derivations

Since `nix flake check` doesn't produce a `result` symlink, it doesn't
actually need to build/substitute derivations that are already known
to have succeeded, i.e. that are substitutable.

This can speed up CI jobs in cases where the derivations have already
been built by other jobs. For instance, a command like

  nix flake check github:NixOS/hydra/aa62c7f7db31753f0cde690f8654dd1907fc0ce2

should no longer build anything because the outputs are already in
cache.nixos.org.
This commit is contained in:
Eelco Dolstra 2025-07-04 17:07:18 +02:00
parent 1df17735f5
commit 5c9592194c

View file

@ -833,8 +833,31 @@ struct CmdFlakeCheck : FlakeCommand
if (build && !drvPaths.empty()) {
Activity act(*logger, lvlInfo, actUnknown,
fmt("running %d flake checks", drvPaths.size()));
store->buildPaths(drvPaths);
auto missing = store->queryMissing(drvPaths);
/* This command doesn't need to actually substitute
derivation outputs if they're missing but
substitutable. So filter out derivations that are
substitutable or already built. */
std::vector<DerivedPath> toBuild;
for (auto & path : drvPaths) {
std::visit(overloaded {
[&](const DerivedPath::Built & bfd) {
auto drvPathP = std::get_if<DerivedPath::Opaque>(&*bfd.drvPath);
if (!drvPathP || missing.willBuild.contains(drvPathP->path))
toBuild.push_back(path);
},
[&](const DerivedPath::Opaque & bo) {
if (!missing.willSubstitute.contains(bo.path))
toBuild.push_back(path);
},
}, path.raw());
}
store->buildPaths(toBuild);
}
if (hasErrors)
throw Error("some errors were encountered during the evaluation");