Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix follow path checking at depths greater than 2 #8819

Merged
merged 4 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/manual/src/release-notes/rl-next.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@

- Introduce a new [`outputOf`](@docroot@/language/builtins.md#builtins-outputOf) builtin.
It is part of the [`dynamic-derivations`](@docroot@/contributing/experimental-features.md#xp-feature-dynamic-derivations) experimental feature.

- Flake follow paths at depths greater than 2 are now handled correctly, preventing "follows a non-existent input" errors.
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
82 changes: 82 additions & 0 deletions tests/flakes/follow-paths.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,85 @@ 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'"
roberth marked this conversation as resolved.
Show resolved Hide resolved
nix flake lock $flakeFollowsA 2>&1 | grep "warning: input 'B' has an override for a non-existent input 'invalid2'"
roberth marked this conversation as resolved.
Show resolved Hide resolved

# Now test follow path overloading
RealityAnomaly marked this conversation as resolved.
Show resolved Hide resolved
# This tests a lockfile checking regression https://github.com/NixOS/nix/pull/8819
#
# We construct the following graph, where p->q means p has input q.
# A double edge means that the edge gets overridden using `follows`.
#
# A
# / \
# / \
# v v
# B ==> C --- follows declared in A
# \\ /
# \\/ --- follows declared in B
# v
# D
#
# The message was
# error: input 'B/D' follows a non-existent input 'B/C/D'
#
# Note that for `B` to resolve its follow for `D`, it needs `C/D`, for which it needs to resolve the follow on `C` first.
flakeFollowsOverloadA=$TEST_ROOT/follows/overload/flakeA
roberth marked this conversation as resolved.
Show resolved Hide resolved
flakeFollowsOverloadB=$TEST_ROOT/follows/overload/flakeA/flakeB
roberth marked this conversation as resolved.
Show resolved Hide resolved
flakeFollowsOverloadC=$TEST_ROOT/follows/overload/flakeA/flakeB/flakeC
roberth marked this conversation as resolved.
Show resolved Hide resolved
flakeFollowsOverloadD=$TEST_ROOT/follows/overload/flakeA/flakeB/flakeC/flakeD
roberth marked this conversation as resolved.
Show resolved Hide resolved

# Test following path flakerefs.
createGitRepo $flakeFollowsOverloadA
roberth marked this conversation as resolved.
Show resolved Hide resolved
mkdir -p $flakeFollowsOverloadB
roberth marked this conversation as resolved.
Show resolved Hide resolved
mkdir -p $flakeFollowsOverloadC
roberth marked this conversation as resolved.
Show resolved Hide resolved
mkdir -p $flakeFollowsOverloadD
roberth marked this conversation as resolved.
Show resolved Hide resolved

cat > $flakeFollowsOverloadD/flake.nix <<EOF
roberth marked this conversation as resolved.
Show resolved Hide resolved
{
description = "Flake D";
inputs = {};
outputs = { ... }: {};
}
EOF

cat > $flakeFollowsOverloadC/flake.nix <<EOF
roberth marked this conversation as resolved.
Show resolved Hide resolved
{
description = "Flake C";
inputs.D.url = "path:./flakeD";
outputs = { ... }: {};
}
EOF

cat > $flakeFollowsOverloadB/flake.nix <<EOF
roberth marked this conversation as resolved.
Show resolved Hide resolved
{
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
roberth marked this conversation as resolved.
Show resolved Hide resolved
{
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 \
roberth marked this conversation as resolved.
Show resolved Hide resolved
flakeB/flakeC/flake.nix flakeB/flakeC/flakeD/flake.nix

nix flake metadata $flakeFollowsOverloadA
roberth marked this conversation as resolved.
Show resolved Hide resolved
nix flake update $flakeFollowsOverloadA
roberth marked this conversation as resolved.
Show resolved Hide resolved
nix flake lock $flakeFollowsOverloadA
roberth marked this conversation as resolved.
Show resolved Hide resolved