diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2023-01-10 14:35:06 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2023-01-10 14:35:06 +0100 |
commit | 8e923bf4c53233aba9e21c06b5da0d800da37e40 (patch) | |
tree | f8bea47a70b46982400e55255590d567bc334e36 /src/nix/why-depends.cc | |
parent | 5c97b5a3988c7dd28e617734c2eba669ee0c1288 (diff) | |
parent | 877e7a5ccf21279d9e027867e63181b2b9a6a15a (diff) |
Merge remote-tracking branch 'origin/master' into fix-7417
Diffstat (limited to 'src/nix/why-depends.cc')
-rw-r--r-- | src/nix/why-depends.cc | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/src/nix/why-depends.cc b/src/nix/why-depends.cc index 661df965e..76125e5e4 100644 --- a/src/nix/why-depends.cc +++ b/src/nix/why-depends.cc @@ -95,23 +95,13 @@ struct CmdWhyDepends : SourceExprCommand * to build. */ auto dependency = parseInstallable(store, _dependency); - auto derivedDependency = dependency->toDerivedPath(); - auto optDependencyPath = std::visit(overloaded { - [](const DerivedPath::Opaque & nodrv) -> std::optional<StorePath> { - return { nodrv.path }; - }, - [&](const DerivedPath::Built & hasdrv) -> std::optional<StorePath> { - if (hasdrv.outputs.size() != 1) { - throw Error("argument '%s' should evaluate to one store path", dependency->what()); - } - auto outputMap = store->queryPartialDerivationOutputMap(hasdrv.drvPath); - auto maybePath = outputMap.find(*hasdrv.outputs.begin()); - if (maybePath == outputMap.end()) { - throw Error("unexpected end of iterator"); - } - return maybePath->second; - }, - }, derivedDependency.path.raw()); + 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); |