mirror of
https://github.com/NixOS/nix.git
synced 2025-11-22 18:29:36 +01:00
Add nix registry resolve command
This commit is contained in:
parent
72dbd43882
commit
063cdb5508
3 changed files with 66 additions and 1 deletions
28
src/nix/registry-resolve.md
Normal file
28
src/nix/registry-resolve.md
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
R""(
|
||||
|
||||
# Examples
|
||||
|
||||
* Resolve the `nixpkgs` and `blender-bin` flakerefs:
|
||||
|
||||
```console
|
||||
# nix registry resolve nixpkgs blender-bin
|
||||
github:NixOS/nixpkgs/nixpkgs-unstable
|
||||
github:edolstra/nix-warez?dir=blender
|
||||
```
|
||||
|
||||
* Resolve an indirect flakeref with a branch override:
|
||||
|
||||
```console
|
||||
# nix registry resolve nixpkgs/25.05
|
||||
github:NixOS/nixpkgs/25.05
|
||||
```
|
||||
|
||||
# Description
|
||||
|
||||
This command resolves indirect flakerefs (e.g. `nixpkgs`) to direct flakerefs (e.g. `github:NixOS/nixpkgs`) using the flake registries. It looks up each provided flakeref in all available registries (flag, user, system, and global) and returns the resolved direct flakeref on a separate line on standard output. It does not fetch any flakes.
|
||||
|
||||
The resolution process may apply multiple redirections if necessary until a direct flakeref is found. If an indirect flakeref cannot be found in any registry, an error will be thrown.
|
||||
|
||||
See the [`nix registry` manual page](./nix3-registry.md) for more details on the registry.
|
||||
|
||||
)""
|
||||
|
|
@ -202,6 +202,40 @@ struct CmdRegistryPin : RegistryCommand, EvalCommand
|
|||
}
|
||||
};
|
||||
|
||||
struct CmdRegistryResolve : StoreCommand
|
||||
{
|
||||
std::vector<std::string> urls;
|
||||
|
||||
std::string description() override
|
||||
{
|
||||
return "resolve flake references using the registry";
|
||||
}
|
||||
|
||||
std::string doc() override
|
||||
{
|
||||
return
|
||||
#include "registry-resolve.md"
|
||||
;
|
||||
}
|
||||
|
||||
CmdRegistryResolve()
|
||||
{
|
||||
expectArgs({
|
||||
.label = "flake-refs",
|
||||
.handler = {&urls},
|
||||
});
|
||||
}
|
||||
|
||||
void run(nix::ref<nix::Store> store) override
|
||||
{
|
||||
for (auto & url : urls) {
|
||||
auto ref = parseFlakeRef(fetchSettings, url);
|
||||
auto resolved = ref.resolve(fetchSettings, *store);
|
||||
logger->cout("%s", resolved.to_string());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct CmdRegistry : NixMultiCommand
|
||||
{
|
||||
CmdRegistry()
|
||||
|
|
@ -212,6 +246,7 @@ struct CmdRegistry : NixMultiCommand
|
|||
{"add", []() { return make_ref<CmdRegistryAdd>(); }},
|
||||
{"remove", []() { return make_ref<CmdRegistryRemove>(); }},
|
||||
{"pin", []() { return make_ref<CmdRegistryPin>(); }},
|
||||
{"resolve", []() { return make_ref<CmdRegistryResolve>(); }},
|
||||
})
|
||||
{
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue