Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/nix/registry-resolve.md
Original file line number Diff line number Diff line change
@@ -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.

)""
35 changes: 35 additions & 0 deletions src/nix/registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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>(); }},
})
{
}
Expand Down
4 changes: 3 additions & 1 deletion tests/functional/flakes/flakes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,17 @@ nix flake lock "$flake3Dir"
nix flake update --flake "$flake3Dir" --override-flake flake2 nixpkgs
[[ -n $(git -C "$flake3Dir" diff master || echo failed) ]]

# Testing the nix CLI
# Test `nix registry` commands.
nix registry add flake1 flake3
[[ $(nix registry list | wc -l) == 5 ]]
[[ $(nix registry resolve flake1) = "git+file://$percentEncodedFlake3Dir" ]]
nix registry pin flake1
[[ $(nix registry list | wc -l) == 5 ]]
nix registry pin flake1 flake3
[[ $(nix registry list | wc -l) == 5 ]]
nix registry remove flake1
[[ $(nix registry list | wc -l) == 4 ]]
[[ $(nix registry resolve flake1) = "git+file://$flake1Dir" ]]

# Test 'nix registry list' with a disabled global registry.
nix registry add user-flake1 git+file://"$flake1Dir"
Expand Down
Loading