source ./common.sh requireGit flakeFollowsA=$TEST_ROOT/follows/flakeA flakeFollowsB=$TEST_ROOT/follows/flakeA/flakeB flakeFollowsC=$TEST_ROOT/follows/flakeA/flakeB/flakeC flakeFollowsD=$TEST_ROOT/follows/flakeA/flakeD flakeFollowsE=$TEST_ROOT/follows/flakeA/flakeE # Test following path flakerefs. createGitRepo $flakeFollowsA mkdir -p $flakeFollowsB mkdir -p $flakeFollowsC mkdir -p $flakeFollowsD mkdir -p $flakeFollowsE cat > $flakeFollowsA/flake.nix < $flakeFollowsB/flake.nix < $flakeFollowsC/flake.nix < $flakeFollowsD/flake.nix < $flakeFollowsE/flake.nix < $flakeFollowsA/flake.nix < $flakeFollowsA/flake.nix <&1 | grep 'points outside' # Non-existant follows should print a warning. cat >$flakeFollowsA/flake.nix <&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 # 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" 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" < "$flakeFollowsOverloadC/flake.nix" < "$flakeFollowsOverloadB/flake.nix" < "$flakeFollowsOverloadA/flake.nix" < $flakeFollowsD/flake.nix { outputs = _: {}; } EOF cat < $flakeFollowsC/flake.nix { inputs.D.url = "path:nosuchflake"; outputs = _: {}; } EOF cat < $flakeFollowsB/flake.nix { inputs.C.url = "path:$flakeFollowsC"; outputs = _: {}; } EOF cat < $flakeFollowsA/flake.nix { inputs.B.url = "path:$flakeFollowsB"; inputs.D.url = "path:$flakeFollowsD"; inputs.B.inputs.C.inputs.D.follows = "D"; outputs = _: {}; } EOF nix flake lock $flakeFollowsA [[ $(jq -c .nodes.C.inputs.D $flakeFollowsA/flake.lock) = '["D"]' ]] # Test overlapping flake follows: B has D follow C/D, while A has B/C follow C cat < $flakeFollowsC/flake.nix { inputs.D.url = "path:$flakeFollowsD"; outputs = _: {}; } EOF cat < $flakeFollowsB/flake.nix { inputs.C.url = "path:nosuchflake"; inputs.D.url = "path:nosuchflake"; inputs.D.follows = "C/D"; outputs = _: {}; } EOF cat < $flakeFollowsA/flake.nix { inputs.B.url = "path:$flakeFollowsB"; inputs.C.url = "path:$flakeFollowsC"; inputs.B.inputs.C.follows = "C"; outputs = _: {}; } EOF # bug was not triggered without recreating the lockfile nix flake update --flake $flakeFollowsA [[ $(jq -c .nodes.B.inputs.D $flakeFollowsA/flake.lock) = '["B","C","D"]' ]] cat < $flakeFollowsA/flake.nix { inputs.B.url = "path:$flakeFollowsB"; inputs.C.url = "path:$flakeFollowsC"; inputs.B.inputs.C.inputs.E.follows = "C"; outputs = _: {}; } EOF cat < $flakeFollowsB/flake.nix { inputs.C.url = "path:$flakeFollowsC"; outputs = _: {}; } EOF nix flake update --flake $flakeFollowsA 2>&1 | grepQuiet "warning: input 'B/C' has an override for a non-existent input 'E'" # Test for Nested follows cause flake interactions to update the nested input #460 for letter in {A..E}; do path="flakeFollows${letter}" rm -f "${!path}"/flake.lock done cat < $flakeFollowsA/flake.nix { inputs = { B.url = "path:$flakeFollowsB"; C = { url = "path:$flakeFollowsC"; inputs.D.inputs.E.follows = "B"; }; }; outputs = _: {}; } EOF cat < $flakeFollowsB/flake.nix { outputs = _: {}; } EOF cat < $flakeFollowsC/flake.nix { inputs = { D.url = "path:$flakeFollowsD"; }; outputs = _: {}; } EOF cat < $flakeFollowsD/flake.nix { inputs = { E.url = "path:$flakeFollowsE"; }; outputs = _: {}; } EOF # Lockfiles are cleared, initially the dependency needs to be fetched. out="$(nix --verbose flake show path:$flakeFollowsA 2>&1)" echo "$out" [[ "$out" = *$'\n'"fetching path input 'path:"*"/flakeD'"$'\n'* ]] # But on another flake command it doesn't. out="$(nix --verbose flake show path:$flakeFollowsA 2>&1)" [[ "$out" != *$'\n'"fetching path input 'path:"*"/flakeD'"$'\n'* ]] # Make sure the nested override is actually correct in this testcase. [[ "$(nix flake metadata path:$flakeFollowsA --json | jq '.locks.nodes.D.inputs.E|.[]' -r)" = "B" ]]