1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 14:21:48 +02:00

Don't allow flake inputs to have both a flakeref and a follows

Having both doesn't make sense so it's best to disallow it. If this
causes issues we could turn into a warning.
This commit is contained in:
Eelco Dolstra 2025-06-12 20:38:51 +02:00
parent 637c4f3ad7
commit b415faceca
2 changed files with 15 additions and 1 deletions

View file

@ -170,6 +170,9 @@ static FlakeInput parseFlakeInput(
input.ref = parseFlakeRef(state.fetchSettings, *url, {}, true, input.isFlake, true); input.ref = parseFlakeRef(state.fetchSettings, *url, {}, true, input.isFlake, true);
} }
if (input.ref && input.follows)
throw Error("flake input has both a flake reference and a follows attribute, at %s", state.positions[pos]);
return input; return input;
} }

View file

@ -401,7 +401,6 @@ EOF
cat <<EOF > $flakeFollowsB/flake.nix cat <<EOF > $flakeFollowsB/flake.nix
{ {
inputs.C.url = "path:nosuchflake"; inputs.C.url = "path:nosuchflake";
inputs.D.url = "path:nosuchflake";
inputs.D.follows = "C/D"; inputs.D.follows = "C/D";
outputs = _: {}; outputs = _: {};
} }
@ -419,3 +418,15 @@ EOF
nix flake lock $flakeFollowsA --recreate-lock-file nix flake lock $flakeFollowsA --recreate-lock-file
[[ $(jq -c .nodes.B.inputs.D $flakeFollowsA/flake.lock) = '["B","C","D"]' ]] [[ $(jq -c .nodes.B.inputs.D $flakeFollowsA/flake.lock) = '["B","C","D"]' ]]
# Check that you can't have both a flakeref and a follows attribute on an input.
cat <<EOF > $flakeFollowsB/flake.nix
{
inputs.C.url = "path:nosuchflake";
inputs.D.url = "path:nosuchflake";
inputs.D.follows = "C/D";
outputs = _: {};
}
EOF
expectStderr 1 nix flake lock $flakeFollowsA --recreate-lock-file | grepQuiet "flake input has both a flake reference and a follows attribute"