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

Warn against the use of indirect flakerefs in flake inputs

This commit is contained in:
Eelco Dolstra 2025-04-25 21:16:27 +02:00
parent 97487c58a1
commit ca1b2dc617

View file

@ -740,6 +740,27 @@ LockedFlake lockFlake(
use --no-write-lock-file. */
auto ref = (input2.ref && explicitCliOverrides.contains(inputAttrPath)) ? *input2.ref : *input.ref;
/* Warn against the use of indirect flakerefs
(but only at top-level since we don't want
to annoy users about flakes that are not
under their control). */
auto warnRegistry = [&](const FlakeRef & resolvedRef)
{
if (inputAttrPath.size() == 1 && !input.ref->input.isDirect()) {
std::ostringstream s;
printLiteralString(s, resolvedRef.to_string());
warn(
"Flake input '%1%' uses the flake registry. "
"Using the registry in flake inputs is deprecated. "
"To make your flake future-proof, add the following to '%2%':\n"
"\n"
" inputs.%1%.url = %3%;",
inputAttrPathS,
flake.path,
s.str());
}
};
if (input.isFlake) {
auto inputFlake = getInputFlake(*input.ref);
@ -771,6 +792,8 @@ LockedFlake lockFlake(
oldLock ? followsPrefix : inputAttrPath,
inputFlake.path,
false);
warnRegistry(inputFlake.resolvedRef);
}
else {
@ -783,6 +806,8 @@ LockedFlake lockFlake(
auto [accessor, resolvedRef, lockedRef] = fetchOrSubstituteTree(
state, *input.ref, useRegistries, flakeCache);
warnRegistry(resolvedRef);
// FIXME: allow input to be lazy.
auto storePath = copyInputToStore(state, lockedRef.input, input.ref->input, accessor);