From 811f3e8605ce779830fa4770cd7ef3cda81afdf1 Mon Sep 17 00:00:00 2001 From: Alexander Bantyev Date: Wed, 30 Jun 2021 22:14:41 +0300 Subject: [PATCH] nix registry pin: add a way to pin to a custom locked --- src/libfetchers/registry.cc | 7 +++++++ src/libfetchers/registry.hh | 3 +++ src/nix/registry.cc | 19 +++++++++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/libfetchers/registry.cc b/src/libfetchers/registry.cc index 74376adc0..c2dfa9dc6 100644 --- a/src/libfetchers/registry.cc +++ b/src/libfetchers/registry.cc @@ -124,6 +124,13 @@ std::shared_ptr getUserRegistry() return userRegistry; } +std::shared_ptr getCustomRegistry(Path p) +{ + static auto customRegistry = + Registry::read(p, Registry::Custom); + return customRegistry; +} + static std::shared_ptr flagRegistry = std::make_shared(Registry::Flag); diff --git a/src/libfetchers/registry.hh b/src/libfetchers/registry.hh index 1077af020..cde22dff6 100644 --- a/src/libfetchers/registry.hh +++ b/src/libfetchers/registry.hh @@ -14,6 +14,7 @@ struct Registry User = 1, System = 2, Global = 3, + Custom = 4, }; RegistryType type; @@ -48,6 +49,8 @@ typedef std::vector> Registries; std::shared_ptr getUserRegistry(); +std::shared_ptr getCustomRegistry(Path p); + Path getUserRegistryPath(); Registries getRegistries(ref store); diff --git a/src/nix/registry.cc b/src/nix/registry.cc index 4400cc8dc..ec80dc0bc 100644 --- a/src/nix/registry.cc +++ b/src/nix/registry.cc @@ -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 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);