From b415faceca9ea32823ec3701580dc3c1d2530d82 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 12 Jun 2025 20:38:51 +0200 Subject: [PATCH] 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. --- src/libflake/flake.cc | 3 +++ tests/functional/flakes/follow-paths.sh | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/libflake/flake.cc b/src/libflake/flake.cc index 2b73dbf0b..e59649fec 100644 --- a/src/libflake/flake.cc +++ b/src/libflake/flake.cc @@ -170,6 +170,9 @@ static FlakeInput parseFlakeInput( 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; } diff --git a/tests/functional/flakes/follow-paths.sh b/tests/functional/flakes/follow-paths.sh index abc09dfc2..cf27681cb 100755 --- a/tests/functional/flakes/follow-paths.sh +++ b/tests/functional/flakes/follow-paths.sh @@ -401,7 +401,6 @@ EOF cat < $flakeFollowsB/flake.nix { inputs.C.url = "path:nosuchflake"; - inputs.D.url = "path:nosuchflake"; inputs.D.follows = "C/D"; outputs = _: {}; } @@ -419,3 +418,15 @@ EOF nix flake lock $flakeFollowsA --recreate-lock-file [[ $(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 < $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"