Skip to content

Commit

Permalink
Fix why-depends for CA derivations (again)
Browse files Browse the repository at this point in the history
This has the same goal as b13fd4c,but
achieves it in a different way in order to not break
`nix why-depends --derivation`.
  • Loading branch information
Théophane Hufschmitt committed Jan 2, 2023
1 parent 6a90ef0 commit 93b5d8d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
5 changes: 1 addition & 4 deletions src/libcmd/installables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -931,10 +931,7 @@ std::vector<std::pair<std::shared_ptr<Installable>, BuiltPathWithResult>> Instal
DrvOutput outputId { *outputHash, output };
auto realisation = store->queryRealisation(outputId);
if (!realisation)
throw Error(
"cannot operate on an output of the "
"unbuilt derivation '%s'",
outputId.to_string());
throw MissingRealisation(outputId);
outputs.insert_or_assign(output, realisation->outPath);
} else {
// If ca-derivations isn't enabled, assume that
Expand Down
10 changes: 10 additions & 0 deletions src/libstore/realisation.hh
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,14 @@ struct RealisedPath {
GENERATE_CMP(RealisedPath, me->raw);
};

class MissingRealisation : public Error
{
public:
MissingRealisation(DrvOutput & outputId)
: Error( "cannot operate on an output of the "
"unbuilt derivation '%s'",
outputId.to_string())
{}
};

}
5 changes: 1 addition & 4 deletions src/libstore/remote-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -879,10 +879,7 @@ std::vector<BuildResult> RemoteStore::buildPathsWithResults(
auto realisation =
queryRealisation(outputId);
if (!realisation)
throw Error(
"cannot operate on an output of unbuilt "
"content-addressed derivation '%s'",
outputId.to_string());
throw MissingRealisation(outputId);
res.builtOutputs.emplace(realisation->id, *realisation);
} else {
// If ca-derivations isn't enabled, assume that
Expand Down
18 changes: 13 additions & 5 deletions src/nix/why-depends.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,27 @@ struct CmdWhyDepends : SourceExprCommand
* to build.
*/
auto dependency = parseInstallable(store, _dependency);
auto dependencyPath = Installable::toStorePath(getEvalStore(), store, Realise::Derivation, operateOn, dependency);
auto dependencyPathHash = dependencyPath.hashPart();
auto optDependencyPath = [&]() -> std::optional<StorePath> {
try {
return {Installable::toStorePath(getEvalStore(), store, Realise::Derivation, operateOn, dependency)};
} catch (MissingRealisation &) {
return std::nullopt;
}
}();

StorePathSet closure;
store->computeFSClosure({packagePath}, closure, false, false);

if (!closure.count(dependencyPath)) {
if (!optDependencyPath.has_value() || !closure.count(*optDependencyPath)) {
printError("'%s' does not depend on '%s'",
store->printStorePath(packagePath),
store->printStorePath(dependencyPath));
package->what(),
dependency->what());
return;
}

auto dependencyPath = optDependencyPath.value();
auto dependencyPathHash = dependencyPath.hashPart();

stopProgressBar(); // FIXME

auto accessor = store->getFSAccessor();
Expand Down

0 comments on commit 93b5d8d

Please sign in to comment.