2021-03-09 09:11:25 +00:00
|
|
|
#include "command.hh"
|
|
|
|
#include "common-args.hh"
|
|
|
|
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
|
|
|
using namespace nix;
|
|
|
|
|
|
|
|
struct CmdRealisation : virtual NixMultiCommand
|
|
|
|
{
|
|
|
|
CmdRealisation() : MultiCommand(RegisterCommand::getCommandsFor({"realisation"}))
|
|
|
|
{ }
|
|
|
|
|
|
|
|
std::string description() override
|
|
|
|
{
|
|
|
|
return "manipulate a Nix realisation";
|
|
|
|
}
|
|
|
|
|
|
|
|
Category category() override { return catUtility; }
|
|
|
|
|
|
|
|
void run() override
|
|
|
|
{
|
|
|
|
if (!command)
|
|
|
|
throw UsageError("'nix realisation' requires a sub-command.");
|
|
|
|
command->second->run();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static auto rCmdRealisation = registerCommand<CmdRealisation>("realisation");
|
|
|
|
|
2021-05-17 06:45:08 +00:00
|
|
|
struct CmdRealisationInfo : BuiltPathsCommand, MixJSON
|
2021-03-09 09:11:25 +00:00
|
|
|
{
|
|
|
|
std::string description() override
|
|
|
|
{
|
|
|
|
return "query information about one or several realisations";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string doc() override
|
|
|
|
{
|
|
|
|
return
|
|
|
|
#include "realisation/info.md"
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
Category category() override { return catSecondary; }
|
|
|
|
|
2021-09-27 08:53:09 +00:00
|
|
|
void run(ref<Store> store, BuiltPaths && paths) override
|
2021-03-09 09:11:25 +00:00
|
|
|
{
|
2023-03-17 14:33:48 +00:00
|
|
|
experimentalFeatureSettings.require(Xp::CaDerivations);
|
2021-05-17 06:45:08 +00:00
|
|
|
RealisedPath::Set realisations;
|
|
|
|
|
|
|
|
for (auto & builtPath : paths) {
|
|
|
|
auto theseRealisations = builtPath.toRealisedPaths(*store);
|
|
|
|
realisations.insert(theseRealisations.begin(), theseRealisations.end());
|
|
|
|
}
|
|
|
|
|
2021-03-09 09:11:25 +00:00
|
|
|
if (json) {
|
|
|
|
nlohmann::json res = nlohmann::json::array();
|
2021-05-17 06:45:08 +00:00
|
|
|
for (auto & path : realisations) {
|
2021-03-09 09:11:25 +00:00
|
|
|
nlohmann::json currentPath;
|
|
|
|
if (auto realisation = std::get_if<Realisation>(&path.raw))
|
|
|
|
currentPath = realisation->toJSON();
|
|
|
|
else
|
|
|
|
currentPath["opaquePath"] = store->printStorePath(path.path());
|
|
|
|
|
|
|
|
res.push_back(currentPath);
|
|
|
|
}
|
2023-03-02 14:02:24 +00:00
|
|
|
logger->cout("%s", res);
|
2021-03-09 09:11:25 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-05-17 06:45:08 +00:00
|
|
|
for (auto & path : realisations) {
|
2021-03-09 09:11:25 +00:00
|
|
|
if (auto realisation = std::get_if<Realisation>(&path.raw)) {
|
2023-03-02 14:02:24 +00:00
|
|
|
logger->cout("%s %s",
|
|
|
|
realisation->id.to_string(),
|
|
|
|
store->printStorePath(realisation->outPath));
|
2021-03-09 09:11:25 +00:00
|
|
|
} else
|
2023-03-02 14:02:24 +00:00
|
|
|
logger->cout("%s", store->printStorePath(path.path()));
|
2021-03-09 09:11:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static auto rCmdRealisationInfo = registerCommand2<CmdRealisationInfo>({"realisation", "info"});
|