diff --git a/src/libexpr/flake/flake.cc b/src/libexpr/flake/flake.cc index 920726b73..b97780a9c 100644 --- a/src/libexpr/flake/flake.cc +++ b/src/libexpr/flake/flake.cc @@ -373,6 +373,29 @@ LockedFlake lockFlake( { debug("computing lock file node '%s'", printInputPath(inputPathPrefix)); + auto overrides2 = overrides; + for (auto & [inputPath, inputOverride] : overrides2) { + auto inputPath2(inputPath); + auto follow = inputPath2.back(); + inputPath2.pop_back(); + if (inputPath2 == inputPathPrefix + && flakeInputs.find(follow) == flakeInputs.end() + ) { + std::string root; + for (auto & element : inputPath2) { + root.append(element); + if (element != inputPath2.back()) { + root.append(".inputs."); + } + } + throw Error( + "%s has a `follows'-declaration for a non-existant input %s!", + root, + follow + ); + } + } + /* Get the overrides (i.e. attributes of the form 'inputs.nixops.inputs.nixpkgs.url = ...'). */ for (auto & [id, input] : flakeInputs) { diff --git a/tests/flakes.sh b/tests/flakes.sh index 35cf4d8e7..868c410f4 100644 --- a/tests/flakes.sh +++ b/tests/flakes.sh @@ -801,6 +801,8 @@ nix flake metadata $flakeFollowsA nix flake update $flakeFollowsA +nix flake lock $flakeFollowsA + oldLock="$(cat "$flakeFollowsA/flake.lock")" # Ensure that locking twice doesn't change anything @@ -823,7 +825,6 @@ cat > $flakeFollowsA/flake.nix <$flakeFollowsA/flake.nix <&1 | grep "error: B has a \`follows'-declaration for a non-existant input invalid!"