aboutsummaryrefslogtreecommitdiff
path: root/src/nix/registry.cc
diff options
context:
space:
mode:
authorDelan Azabani <delan@azabani.com>2024-07-02 07:20:01 +0000
committerGerrit Code Review <gerrit@localhost>2024-07-02 07:20:01 +0000
commit865a3732faca16a79bf24982011adf100de04463 (patch)
tree8021062dbf69743071847d4f3337f4be6ee984b1 /src/nix/registry.cc
parentd3286d0990da111c536c2f879d8f9cbbd650ebae (diff)
parentb2944d93a6d95810f0aef09e9ac44b95e2712554 (diff)
Merge "Reject fully-qualified URLs in 'from' argument of `nix registry add`" into main
Diffstat (limited to 'src/nix/registry.cc')
-rw-r--r--src/nix/registry.cc8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/nix/registry.cc b/src/nix/registry.cc
index f509ccae8..9619b85d4 100644
--- a/src/nix/registry.cc
+++ b/src/nix/registry.cc
@@ -5,6 +5,7 @@
#include "flake/flake.hh"
#include "store-api.hh"
#include "fetchers.hh"
+#include "url-parts.hh"
#include "registry.hh"
using namespace nix;
@@ -109,7 +110,14 @@ struct CmdRegistryAdd : MixEvalArgs, Command, RegistryCommand
void run() override
{
+ std::smatch match;
+ if (!std::regex_match(fromUrl, match, flakeShorthandRegex)) {
+ throw UsageError("'from-url' argument must be a shorthand like 'nixpkgs' or 'nixpkgs/nixos-20.03'");
+ }
auto fromRef = parseFlakeRef(fromUrl);
+ if (fromRef.input.direct) {
+ throw UsageError("'from-url' argument must be an indirect flakeref like 'nixpkgs' or 'flake:nixpkgs'");
+ }
auto toRef = parseFlakeRef(toUrl);
auto registry = getRegistry();
fetchers::Attrs extraAttrs;