diff options
author | julia <midnight@trainwit.ch> | 2024-05-15 19:11:32 +1000 |
---|---|---|
committer | julia <midnight@trainwit.ch> | 2024-05-18 12:27:23 +1000 |
commit | 7a3745b07607d3fc85fb5a0a08832ab078080884 (patch) | |
tree | bc82a0a28077bb320a7a32c9d4bc7de9b213b47d /tests | |
parent | 236466faf385f98f3639ec04147c171774d03726 (diff) |
Deprecate the online flake registries and vendor the default registry
Fixes #183, #110, #116.
The default flake-registry option becomes 'vendored', and refers
to a vendored flake-registry.json file in the install path.
Vendored copy of the flake-registry is from github:NixOS/flake-registry
at commit 9c69f7bd2363e71fe5cd7f608113290c7614dcdd.
Change-Id: I752b81c85ebeaab4e582ac01c239d69d65580f37
Diffstat (limited to 'tests')
-rw-r--r-- | tests/functional/flakes/flake-registry.sh | 72 | ||||
-rw-r--r-- | tests/functional/meson.build | 1 | ||||
-rw-r--r-- | tests/nixos/github-flakes.nix | 2 |
3 files changed, 75 insertions, 0 deletions
diff --git a/tests/functional/flakes/flake-registry.sh b/tests/functional/flakes/flake-registry.sh new file mode 100644 index 000000000..73ab353bf --- /dev/null +++ b/tests/functional/flakes/flake-registry.sh @@ -0,0 +1,72 @@ +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 %1 diff --git a/tests/functional/meson.build b/tests/functional/meson.build index 1e68cfe8c..a13dee001 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -69,6 +69,7 @@ functional_tests_scripts = [ 'flakes/unlocked-override.sh', 'flakes/absolute-paths.sh', 'flakes/build-paths.sh', + 'flakes/flake-registry.sh', 'flakes/flake-in-submodule.sh', 'gc.sh', 'nix-collect-garbage-d.sh', diff --git a/tests/nixos/github-flakes.nix b/tests/nixos/github-flakes.nix index 1954208b9..e3437c5e8 100644 --- a/tests/nixos/github-flakes.nix +++ b/tests/nixos/github-flakes.nix @@ -146,6 +146,8 @@ in virtualisation.additionalPaths = [ pkgs.hello pkgs.fuse ]; virtualisation.memorySize = 4096; nix.settings.substituters = lib.mkForce [ ]; + # note: URL flake-registries are currently deprecated. + nix.settings.flake-registry = "https://channels.nixos.org/flake-registry.json"; nix.extraOptions = "experimental-features = nix-command flakes"; networking.hosts.${(builtins.head nodes.github.networking.interfaces.eth1.ipv4.addresses).address} = [ "channels.nixos.org" "api.github.com" "github.com" ]; |