nix registry pin: add a way to pin to a custom locked
This commit is contained in:
parent
093ed47636
commit
811f3e8605
3 changed files with 27 additions and 2 deletions
|
@ -124,6 +124,13 @@ std::shared_ptr<Registry> getUserRegistry()
|
|||
return userRegistry;
|
||||
}
|
||||
|
||||
std::shared_ptr<Registry> getCustomRegistry(Path p)
|
||||
{
|
||||
static auto customRegistry =
|
||||
Registry::read(p, Registry::Custom);
|
||||
return customRegistry;
|
||||
}
|
||||
|
||||
static std::shared_ptr<Registry> flagRegistry =
|
||||
std::make_shared<Registry>(Registry::Flag);
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ struct Registry
|
|||
User = 1,
|
||||
System = 2,
|
||||
Global = 3,
|
||||
Custom = 4,
|
||||
};
|
||||
|
||||
RegistryType type;
|
||||
|
@ -48,6 +49,8 @@ typedef std::vector<std::shared_ptr<Registry>> Registries;
|
|||
|
||||
std::shared_ptr<Registry> getUserRegistry();
|
||||
|
||||
std::shared_ptr<Registry> getCustomRegistry(Path p);
|
||||
|
||||
Path getUserRegistryPath();
|
||||
|
||||
Registries getRegistries(ref<Store> store);
|
||||
|
|
|
@ -152,9 +152,11 @@ struct CmdRegistryPin : RegistryCommand, EvalCommand
|
|||
{
|
||||
std::string url;
|
||||
|
||||
std::string locked;
|
||||
|
||||
std::string description() override
|
||||
{
|
||||
return "pin a flake to its current version in user flake registry";
|
||||
return "pin a flake to its current version in user flake registry or to the current version of a flake URI";
|
||||
}
|
||||
|
||||
std::string doc() override
|
||||
|
@ -167,14 +169,27 @@ struct CmdRegistryPin : RegistryCommand, EvalCommand
|
|||
CmdRegistryPin()
|
||||
{
|
||||
expectArg("url", &url);
|
||||
|
||||
expectArgs({
|
||||
.label = "locked",
|
||||
.optional = true,
|
||||
.handler = {&locked},
|
||||
.completer = {[&](size_t, std::string_view prefix) {
|
||||
completeFlakeRef(getStore(), prefix);
|
||||
}}
|
||||
});
|
||||
}
|
||||
|
||||
void run(nix::ref<nix::Store> store) override
|
||||
{
|
||||
if (locked.empty()) {
|
||||
locked = url;
|
||||
}
|
||||
auto registry = getRegistry();
|
||||
auto ref = parseFlakeRef(url);
|
||||
auto locked_ref = parseFlakeRef(locked);
|
||||
registry->remove(ref.input);
|
||||
auto [tree, resolved] = ref.resolve(store).input.fetch(store);
|
||||
auto [tree, resolved] = locked_ref.resolve(store).input.fetch(store);
|
||||
fetchers::Attrs extraAttrs;
|
||||
if (ref.subdir != "") extraAttrs["dir"] = ref.subdir;
|
||||
registry->add(ref.input, resolved, extraAttrs);
|
||||
|
|
Loading…
Reference in a new issue