testing: migrate flakes/registry.sh

Change-Id: Iba7dd30efc19075a63c505db497b3c0967b47f57
This commit is contained in:
eldritch horrors
2026-02-18 15:25:08 +00:00
parent 4deed5ab35
commit 4fcb434998
3 changed files with 55 additions and 74 deletions
-73
View File
@@ -1,73 +0,0 @@
source ./common.sh
# remove the flake registry from nix.conf, to set to default ("vendored")
sed -i '/flake-registry/d' "$NIX_CONF_DIR/nix.conf"
# Make sure the vendored registry contains the correct amount.
[[ $(nix registry list | wc -l) == 37 ]]
# sanity check, contains the important ones
nix registry list | grep '^global flake:nixpkgs'
nix registry list | grep '^global flake:home-manager'
# it should work the same if we set to vendored directly.
echo 'flake-registry = vendored' >> "$NIX_CONF_DIR/nix.conf"
[[ $(nix registry list | wc -l) == 37 ]]
# sanity check, contains the important ones
nix registry list | grep '^global flake:nixpkgs'
nix registry list | grep '^global flake:home-manager'
# the online flake registry should still work, but it is deprecated.
set -m
# port 0: auto pick a free port, unbufferred output
python3 -u -m http.server 0 --bind 127.0.0.1 > server.out &
# wait for the http server to admit it is working
while ! grep -qP 'port \d+' server.out ; do
echo 'waiting for python http' >&2
sleep 0.2
done
port=$(awk 'match($0,/port ([[:digit:]]+)/, ary) { print ary[1] }' server.out)
sed -i '/flake-registry/d' "$NIX_CONF_DIR/nix.conf"
echo "flake-registry = http://127.0.0.1:$port/flake-registry.json" >> "$NIX_CONF_DIR/nix.conf"
cat <<EOF > flake-registry.json
{
"flakes": [
{
"from": {
"type": "indirect",
"id": "nixpkgs"
},
"to": {
"type": "github",
"owner": "NixOS",
"repo": "nixpkgs"
}
},
{
"from": {
"type": "indirect",
"id": "private-flake"
},
"to": {
"type": "github",
"owner": "fancy-enterprise",
"repo": "private-flake"
}
}
],
"version": 2
}
EOF
[[ $(nix registry list | wc -l) == 2 ]]
nix registry list | grep '^global flake:nixpkgs'
nix registry list | grep '^global flake:private-flake'
# make sure we have a warning:
nix registry list 2>&1 | grep "config option flake-registry referring to a URL is deprecated and will be removed"
kill %python
-1
View File
@@ -38,7 +38,6 @@ functional_tests_scripts = [
'flakes/mercurial.sh',
'flakes/follow-paths.sh',
'flakes/flake-in-submodule.sh',
'flakes/flake-registry.sh',
'gc.sh',
'nix-collect-garbage-d.sh',
'nix-collect-garbage-dry-run.sh',
+55
View File
@@ -0,0 +1,55 @@
from testlib.fixtures.nix import Nix
import aiohttp.web as web
from testlib.fixtures.http_server import http_server
import pytest
import json
@pytest.mark.parametrize("registry", [None, "vendored"])
def test_default_registry(nix: Nix, registry: str | None):
nix.settings.flake_registry = registry
items = nix.nix(["registry", "list"], flake=True).run().ok().stdout_s.splitlines()
# Make sure the vendored registry contains the correct amount.
assert len(items) == 37
# sanity check, contains the important ones
assert any(item.startswith("global flake:nixpkgs") for item in items)
assert any(item.startswith("global flake:home-manager") for item in items)
online_registry = {
"flakes": [
{
"from": {"type": "indirect", "id": "nixpkgs"},
"to": {"type": "github", "owner": "NixOS", "repo": "nixpkgs"},
},
{
"from": {"type": "indirect", "id": "private-flake"},
"to": {"type": "github", "owner": "fancy-enterprise", "repo": "private-flake"},
},
],
"version": 2,
}
class TestOnlineRegistry:
async def get_registry(self, _req: web.Request) -> web.Response:
return web.Response(text=json.dumps(online_registry))
def test_online_registry(self, nix: Nix):
app = web.Application()
app.add_routes([web.get("/flake-registry.json", self.get_registry)])
with http_server(app) as httpd:
nix.settings.flake_registry = f"http://localhost:{httpd.port}/flake-registry.json"
result = nix.nix(["registry", "list"], flake=True).run().ok()
assert result.stdout_s.splitlines() == [
"global flake:nixpkgs github:NixOS/nixpkgs",
"global flake:private-flake github:fancy-enterprise/private-flake",
]
# make sure there's a warning
assert (
"config option flake-registry referring to a URL is deprecated and will be removed"
in result.stderr_s
)