diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 614dee78886..beda99e6070 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -3,6 +3,7 @@ #include "local-fs-store.hh" #include "derivations.hh" #include "nixexpr.hh" +#include "eval.hh" #include "profiles.hh" #include @@ -79,6 +80,13 @@ StorePathsCommand::StorePathsCommand(bool recursive) .category = installablesCategory, .handler = {&all, true}, }); + + addFlag({ + .longName = "include-build-refs", + .description = "Include build-time references of specified path closure.", + .category = installablesCategory, + .handler = {&includeBuildRefs, true}, + }); } void StorePathsCommand::run(ref store) @@ -93,15 +101,38 @@ void StorePathsCommand::run(ref store) } else { + if (!recursive && includeBuildRefs) + throw UsageError("--include-build-refs requires --recursive"); + for (auto & p : toStorePaths(store, realiseMode, operateOn, installables)) storePaths.push_back(p); if (recursive) { + if (includeBuildRefs) { + for (auto & i : installables) { + for (auto & b : i->toBuildables()) { + std::visit(overloaded { + [&](BuildableOpaque bo) { + auto info = store->queryPathInfo(bo.path); + if (info->deriver) + storePaths.push_back(*info->deriver); + else + throw UsageError("Cannot find build references for '%s' without a derivation path", store->printStorePath(bo.path)); + }, + [&](BuildableFromDrv bfd) { + storePaths.push_back(bfd.drvPath); + }, + }, b); + } + } + } + StorePathSet closure; - store->computeFSClosure(StorePathSet(storePaths.begin(), storePaths.end()), closure, false, false); + store->computeFSClosure(StorePathSet(storePaths.begin(), storePaths.end()), closure, false, includeBuildRefs); storePaths.clear(); for (auto & p : closure) - storePaths.push_back(p); + if (!p.isDerivation()) + storePaths.push_back(p); } } diff --git a/src/libcmd/command.hh b/src/libcmd/command.hh index ed6980075f6..e1975595572 100644 --- a/src/libcmd/command.hh +++ b/src/libcmd/command.hh @@ -148,6 +148,8 @@ private: bool recursive = false; bool all = false; + bool includeBuildRefs = false; + protected: Realise realiseMode = Realise::Derivation; diff --git a/src/libcmd/installables.hh b/src/libcmd/installables.hh index f37b3f82924..91334d2f830 100644 --- a/src/libcmd/installables.hh +++ b/src/libcmd/installables.hh @@ -25,6 +25,10 @@ struct BuildableFromDrv { StorePath drvPath; std::map> outputs; nlohmann::json toJSON(ref store) const; + + std::string what() { + return fmt("%s", outputs.at("out") ? outputs.at("out")->name() : "unknown"); + } }; typedef std::variant<