mirror of
https://github.com/NixOS/nix
synced 2025-07-08 06:53:54 +02:00
Add command 'nix store path-from-hash-part'
This exposes the Store::queryPathFromHashPart() interface in the CLI.
This commit is contained in:
parent
a324e9a5c8
commit
61f89e954a
4 changed files with 71 additions and 1 deletions
39
src/nix/path-from-hash-part.cc
Normal file
39
src/nix/path-from-hash-part.cc
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include "command.hh"
|
||||
#include "store-api.hh"
|
||||
|
||||
using namespace nix;
|
||||
|
||||
struct CmdPathFromHashPart : StoreCommand
|
||||
{
|
||||
std::string hashPart;
|
||||
|
||||
CmdPathFromHashPart()
|
||||
{
|
||||
expectArgs({
|
||||
.label = "hash-part",
|
||||
.handler = {&hashPart},
|
||||
});
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
{
|
||||
return "get a store path from its hash part";
|
||||
}
|
||||
|
||||
std::string doc() override
|
||||
{
|
||||
return
|
||||
#include "path-from-hash-part.md"
|
||||
;
|
||||
}
|
||||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
if (auto storePath = store->queryPathFromHashPart(hashPart))
|
||||
logger->cout(store->printStorePath(*storePath));
|
||||
else
|
||||
throw Error("there is no store path corresponding to '%s'", hashPart);
|
||||
}
|
||||
};
|
||||
|
||||
static auto rCmdPathFromHashPart = registerCommand2<CmdPathFromHashPart>({"store", "path-from-hash-part"});
|
20
src/nix/path-from-hash-part.md
Normal file
20
src/nix/path-from-hash-part.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
R""(
|
||||
|
||||
# Examples
|
||||
|
||||
* Return the full store path with the given hash part:
|
||||
|
||||
```console
|
||||
# nix store path-from-hash-part --store https://cache.nixos.org/ 0i2jd68mp5g6h2sa5k9c85rb80sn8hi9
|
||||
/nix/store/0i2jd68mp5g6h2sa5k9c85rb80sn8hi9-hello-2.10
|
||||
```
|
||||
|
||||
# Description
|
||||
|
||||
Given the hash part of a store path (that is, the 32 characters
|
||||
following `/nix/store/`), return the full store path. This is
|
||||
primarily useful in the implementation of binary caches, where a
|
||||
request for a `.narinfo` file only supplies the hash part
|
||||
(e.g. `https://cache.nixos.org/0i2jd68mp5g6h2sa5k9c85rb80sn8hi9.narinfo`).
|
||||
|
||||
)""
|
Loading…
Add table
Add a link
Reference in a new issue