diff --git a/lix/libstore/build/local-derivation-goal.cc b/lix/libstore/build/local-derivation-goal.cc index 9e8ea4ca0..3ed30016c 100644 --- a/lix/libstore/build/local-derivation-goal.cc +++ b/lix/libstore/build/local-derivation-goal.cc @@ -1825,15 +1825,18 @@ try { ); } + outputGraph[scratchOutputs.at(name)] = StorePathSet{}; std::visit( overloaded{/* Since we'll use the already installed versions of these, we can treat them as leaves and ignore any references they have. */ - [&](const AlreadyRegistered &) { - outputGraph[scratchOutputs.at(name)] = StorePathSet{}; - }, + [&](const AlreadyRegistered &) {}, [&](const PerhapsNeedToRegister & refs) { - outputGraph[scratchOutputs.at(name)] = refs.refs; + for (auto & ref : refs.refs) { + if (inverseOutputMap.find(ref) != inverseOutputMap.end()) { + outputGraph[scratchOutputs.at(name)].insert(ref); + } + } } }, *orifu @@ -1844,10 +1847,8 @@ try { topoSort(outputsToSort, {[&](const std::string & name) { StringSet dependencies; for (auto & path : outputGraph.at(scratchOutputs.at(name))) { - auto outputName = inverseOutputMap.find(path); - if (outputName != inverseOutputMap.end()) { - dependencies.insert(outputName->second); - } + auto outputName = inverseOutputMap.at(path); + dependencies.insert(outputName); } return dependencies; }}); diff --git a/lix/libstore/path-tree.cc b/lix/libstore/path-tree.cc index dca268eae..ee6a9a13c 100644 --- a/lix/libstore/path-tree.cc +++ b/lix/libstore/path-tree.cc @@ -265,7 +265,7 @@ static std::map mkGraph( for (auto & node : graph_data) { for (auto & ref : node.second.dependencies) { - graph_data.find(ref)->second.dependents.insert(node.first); + graph_data.at(ref).dependents.insert(node.first); } } diff --git a/tests/functional/check-outputs.nix b/tests/functional/check-outputs.nix index ce260dd4d..3bd382175 100644 --- a/tests/functional/check-outputs.nix +++ b/tests/functional/check-outputs.nix @@ -15,6 +15,18 @@ rec { ''; }; + cycle-with-deps = mkDerivation { + name = "cycle-with-deps"; + inherit dep; + outputs = [ "foo" "bar" ]; + builder = builtins.toFile "builder.sh" '' + mkdir -p $foo/bin $bar/lib + ln -sf $dep $bar/lib + echo $foo > $bar/txt + echo $bar > $foo/txt + ''; + }; + as_dependency = mkDerivation { name = "depends-on-cycle"; inherit cycle; diff --git a/tests/functional/output-cycles.sh b/tests/functional/output-cycles.sh index 1c9369dea..2cd4ef7b9 100644 --- a/tests/functional/output-cycles.sh +++ b/tests/functional/output-cycles.sh @@ -16,3 +16,14 @@ error="$(! nix-build check-outputs.nix -A as_dependency 2>&1)" grepQuiet "cycle detected in build of '.*' in the references of output 'bar' from output 'foo'" <<<"$error" grepQuiet "error: 1 dependencies of derivation" <<<"$error" + +error="$(! nix-build check-outputs.nix -A cycle-with-deps 2>&1)" +grepQuiet "cycle detected in build of '.*' in the references of output 'bar' from output 'foo'" <<<"$error" + +if [[ "$(uname -s)" = Linux ]]; then + echo "$error" + <<<"$error" grepQuiet "/store/.*-cycle-with-deps-bar" + <<<"$error" grepQuiet "└───txt: ….*cycle-with-deps-foo.*" + <<<"$error" grepQuiet " →.*/store/.*-cycle-with-deps-foo" + <<<"$error" grepQuiet " └───txt:.*-cycle-with-deps-bar.*" +fi