Skip to content

Commit

Permalink
Fix follow path checking at depths greater than 2
Browse files Browse the repository at this point in the history
We need to recurse into the input tree to handle follows paths that
trarverse multiple inputs that may or may not be follow paths
themselves.
  • Loading branch information
RealityAnomaly committed Aug 14, 2023
1 parent 5542c1f commit 1ef8008
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libexpr/flake/lockfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ void LockFile::check()

for (auto & [inputPath, input] : inputs) {
if (auto follows = std::get_if<1>(&input)) {
if (!follows->empty() && !get(inputs, *follows))
if (!follows->empty() && !findInput(*follows))
throw Error("input '%s' follows a non-existent input '%s'",
printInputPath(inputPath),
printInputPath(*follows));
Expand Down
63 changes: 63 additions & 0 deletions tests/flakes/follow-paths.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,66 @@ git -C $flakeFollowsA add flake.nix

nix flake lock $flakeFollowsA 2>&1 | grep "warning: input 'B' has an override for a non-existent input 'invalid'"
nix flake lock $flakeFollowsA 2>&1 | grep "warning: input 'B' has an override for a non-existent input 'invalid2'"

# Now test follow path overloading
flakeFollowsOverloadA=$TEST_ROOT/follows/overload/flakeA
flakeFollowsOverloadB=$TEST_ROOT/follows/overload/flakeA/flakeB
flakeFollowsOverloadC=$TEST_ROOT/follows/overload/flakeA/flakeB/flakeC
flakeFollowsOverloadD=$TEST_ROOT/follows/overload/flakeA/flakeB/flakeC/flakeD

# Test following path flakerefs.
createGitRepo $flakeFollowsOverloadA
mkdir -p $flakeFollowsOverloadB
mkdir -p $flakeFollowsOverloadC
mkdir -p $flakeFollowsOverloadD

cat > $flakeFollowsOverloadD/flake.nix <<EOF
{
description = "Flake D";
inputs = {};
outputs = { ... }: {};
}
EOF

cat > $flakeFollowsOverloadC/flake.nix <<EOF
{
description = "Flake C";
inputs.D.url = "path:./flakeD";
outputs = { ... }: {};
}
EOF

cat > $flakeFollowsOverloadB/flake.nix <<EOF
{
description = "Flake B";
inputs = {
C = {
url = "path:./flakeC";
};
D.follows = "C/D";
};
outputs = { ... }: {};
}
EOF

# input B/D should be able to be found...
cat > $flakeFollowsOverloadA/flake.nix <<EOF
{
description = "Flake A";
inputs = {
B = {
url = "path:./flakeB";
inputs.C.follows = "C";
};
C.url = "path:./flakeB/flakeC";
};
outputs = { ... }: {};
}
EOF

git -C $flakeFollowsOverloadA add flake.nix flakeB/flake.nix \
flakeB/flakeC/flake.nix flakeB/flakeC/flakeD/flake.nix

nix flake metadata $flakeFollowsOverloadA
nix flake update $flakeFollowsOverloadA
nix flake lock $flakeFollowsOverloadA

0 comments on commit 1ef8008

Please sign in to comment.