aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/registry-add.md5
-rw-r--r--src/nix/registry.cc8
2 files changed, 11 insertions, 2 deletions
diff --git a/src/nix/registry-add.md b/src/nix/registry-add.md
index a947fa0b3..90b54a596 100644
--- a/src/nix/registry-add.md
+++ b/src/nix/registry-add.md
@@ -31,8 +31,9 @@ R""(
# Description
This command adds an entry to the user registry that maps flake
-reference *from-url* to flake reference *to-url*. If an entry for
-*from-url* already exists, it is overwritten.
+reference *from-url* to flake reference *to-url*, where *from-url*
+must be a shorthand like 'nixpkgs' or 'nixpkgs/nixos-20.03'. If an
+entry for *from-url* already exists, it is overwritten.
Entries can be removed using [`nix registry
remove`](./nix3-registry-remove.md).
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;