Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a
nix realisation
command for working on realisations
Currently only has `nix realisation info`, more to come probably
- Loading branch information
1 parent
1c0e3e4
commit 89013bd
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#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->prepare(); | ||
command->second->run(); | ||
} | ||
}; | ||
|
||
static auto rCmdRealisation = registerCommand<CmdRealisation>("realisation"); | ||
|
||
struct CmdRealisationInfo : RealisedPathsCommand, MixJSON | ||
{ | ||
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; } | ||
|
||
void run(ref<Store> store, std::vector<RealisedPath> paths) override | ||
{ | ||
settings.requireExperimentalFeature("ca-derivations"); | ||
if (json) { | ||
nlohmann::json res = nlohmann::json::array(); | ||
for (auto & path : paths) { | ||
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); | ||
} | ||
std::cout << res.dump(); | ||
} | ||
else { | ||
for (auto & path : paths) { | ||
if (auto realisation = std::get_if<Realisation>(&path.raw)) { | ||
std::cout << | ||
realisation->id.to_string() << " " << | ||
store->printStorePath(realisation->outPath); | ||
} else | ||
std::cout << store->printStorePath(path.path()); | ||
|
||
std::cout << std::endl; | ||
} | ||
} | ||
} | ||
}; | ||
|
||
static auto rCmdRealisationInfo = registerCommand2<CmdRealisationInfo>({"realisation", "info"}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
R"MdBoundary( | ||
# Description | ||
|
||
Display some informations about the given realisation | ||
|
||
# Examples | ||
|
||
Show some information about the realisation of the `hello` package: | ||
|
||
```console | ||
$ nix realisation info nixpkgs#hello --json | ||
[{"id":"sha256:3d382378a00588e064ee30be96dd0fa7e7df7cf3fbcace85a0e7b7dada1eef25!out","outPath":"fd3m7xawvrqcg98kgz5hc2vk3x9q0lh7-hello"}] | ||
``` | ||
|
||
)MdBoundary" |