Skip to content

Commit

Permalink
Allow to disable global flake-registry with ""
Browse files Browse the repository at this point in the history
  • Loading branch information
bew committed Apr 28, 2022
1 parent 35393dc commit 8ceb7b9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/libfetchers/registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ static std::shared_ptr<Registry> getGlobalRegistry(ref<Store> store)
{
static auto reg = [&]() {
auto path = fetchSettings.flakeRegistry.get();
if (path == "") {
return Registry(Registry::Global); // empty registry
}

if (!hasPrefix(path, "/")) {
auto storePath = downloadFile(store, path, "flake-registry.json", false).storePath;
Expand All @@ -173,7 +176,7 @@ Registries getRegistries(ref<Store> store)
registries.push_back(getFlagRegistry());
registries.push_back(getUserRegistry());
registries.push_back(getSystemRegistry());
registries.push_back(getGlobalRegistry(store));
registries.push_back(getGlobalRegistry());
return registries;
}

Expand Down
7 changes: 7 additions & 0 deletions src/libstore/globals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,13 @@ public:
Setting<size_t> narBufferSize{this, 32 * 1024 * 1024, "nar-buffer-size",
"Maximum size of NARs before spilling them to disk."};

Setting<std::string> flakeRegistry{this, "https://github.com/NixOS/flake-registry/raw/master/flake-registry.json", "flake-registry",
R"(
Path or URI of the global flake registry.
Can be set to empty string `""` to disable the global flake registry.
)"};

Setting<bool> allowSymlinkedStore{
this, false, "allow-symlinked-store",
R"(
Expand Down
13 changes: 12 additions & 1 deletion tests/flakes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ nix registry add --registry $registry flake5 hg+file://$flake5Dir
nix registry add --registry $registry nixpkgs flake1
nix registry add --registry $registry templates git+file://$templatesDir

# Test 'nix flake list'.
# Test 'nix registry list'.
[[ $(nix registry list | wc -l) == 7 ]]
nix registry list | grep -q 'global'
nix registry list | grep -q -v 'user' # nothing in user registry

# Test 'nix flake metadata'.
nix flake metadata flake1
Expand Down Expand Up @@ -366,6 +368,15 @@ nix registry pin flake1 flake3
nix registry remove flake1
[[ $(nix registry list | wc -l) == 7 ]]

# 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
[[ $(nix --flake-registry "" registry list | wc -l) == 2 ]]
nix --flake-registry "" registry list | grep -q 'user'
nix --flake-registry "" registry list | grep -q -v 'global' # nothing in global registry
nix registry remove user-flake1
nix registry remove user-flake2

# Test 'nix flake init'.
cat > $templatesDir/flake.nix <<EOF
{
Expand Down

0 comments on commit 8ceb7b9

Please sign in to comment.