From b2944d93a6d95810f0aef09e9ac44b95e2712554 Mon Sep 17 00:00:00 2001 From: Delan Azabani Date: Sat, 22 Jun 2024 23:00:59 +0800 Subject: Reject fully-qualified URLs in 'from' argument of `nix registry add` We previously allowed you to map any flake URL to any other flake URL, including shorthand flakerefs, indirect flake URLs like `flake:nixpkgs`, direct flake URLs like `github:NixOS/nixpkgs`, or local paths. But flake registry entries mapping from direct flake URLs often come from swapping the 'from' and 'to' arguments by accident, and even when created intentionally, they may not actually work correctly. This patch rejects those URLs (and fully-qualified flake: URLs), making it harder to swap the arguments by accident. Fixes #181. Change-Id: I24713643a534166c052719b8770a4edfcfdb8cf3 --- tests/functional/flakes/flakes.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/functional/flakes') diff --git a/tests/functional/flakes/flakes.sh b/tests/functional/flakes/flakes.sh index 68a2fd2ce..97dc6d818 100644 --- a/tests/functional/flakes/flakes.sh +++ b/tests/functional/flakes/flakes.sh @@ -366,6 +366,17 @@ nix registry pin flake1 flake3 nix registry remove flake1 [[ $(nix registry list | wc -l) == 5 ]] +# 'nix registry add' should accept flake shorthands (with or without branch or rev) +# in the from argument, but reject fully-qualified from-urls (direct or indirect). +nix registry add nixpkgz github:NixOS/nixpkgz +nix registry remove nixpkgz +nix registry add nixpkgz/branch github:NixOS/nixpkgz +nix registry remove nixpkgz/branch +nix registry add nixpkgz/branch/1db42b7fe3878f3f5f7a4f2dc210772fd080e205 github:NixOS/nixpkgz +nix registry remove nixpkgz/branch/1db42b7fe3878f3f5f7a4f2dc210772fd080e205 +! nix registry add flake:nixpkgz github:NixOS/nixpkgz +! nix registry add github:NixOS/nixpkgz github:NixOS/nixpkgz + # Test 'nix registry list' with a disabled global registry. nix registry add user-flake1 git+file://$flake1Dir nix registry add user-flake2 git+file://$flake2Dir -- cgit v1.2.3