1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 10:11:47 +02:00

Don't require .tar/.zip extension for tarball flakerefs

Special-casing the file name is rather ugly, so we shouldn't do
that. So now any {file,http,https} URL is handled by
TarballInputScheme, except for non-flake inputs (i.e. inputs that have
the attribute `flake = false`).
This commit is contained in:
Eelco Dolstra 2023-08-01 16:07:20 +02:00
parent dcdd5fed74
commit d9e7758f47
10 changed files with 37 additions and 25 deletions

View file

@ -27,6 +27,7 @@ test_file_flake_input () {
mkdir inputs
echo foo > inputs/test_input_file
echo '{ outputs = { self }: { }; }' > inputs/flake.nix
tar cfa test_input.tar.gz inputs
cp test_input.tar.gz test_input_no_ext
input_tarball_hash="$(nix hash path test_input.tar.gz)"
@ -50,6 +51,9 @@ test_file_flake_input () {
url = "file+file://$PWD/test_input.tar.gz";
flake = false;
};
inputs.flake_no_ext = {
url = "file://$PWD/test_input_no_ext";
};
outputs = { ... }: {};
}
EOF
@ -58,7 +62,7 @@ EOF
nix eval --file - <<EOF
with (builtins.fromJSON (builtins.readFile ./flake.lock));
# Url inputs whose extension doesnt match a known archive format should
# Non-flake inputs whose extension doesnt match a known archive format should
# not be unpacked by default
assert (nodes.no_ext_default_no_unpack.locked.type == "file");
assert (nodes.no_ext_default_no_unpack.locked.unpack or false == false);
@ -75,8 +79,16 @@ EOF
# Explicitely passing the unpack parameter should enforce the desired behavior
assert (nodes.no_ext_explicit_unpack.locked.narHash == nodes.tarball_default_unpack.locked.narHash);
assert (nodes.tarball_explicit_no_unpack.locked.narHash == nodes.no_ext_default_no_unpack.locked.narHash);
# Flake inputs should always be tarballs
assert (nodes.flake_no_ext.locked.type == "tarball");
true
EOF
# Test tarball URLs on the command line.
[[ $(nix flake metadata --json file://$PWD/test_input_no_ext | jq -r .resolved.type) = tarball ]]
popd
[[ -z "${NIX_DAEMON_PACKAGE-}" ]] && return 0