From af35b318f3312ba8147fe2d44eef71ad7924939e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 2 Feb 2020 13:14:34 +0100 Subject: Detect circular flake imports Fixes #2997. --- src/libexpr/flake/flake.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/libexpr/flake/flake.cc') diff --git a/src/libexpr/flake/flake.cc b/src/libexpr/flake/flake.cc index 8b92da2c3..e3fb02591 100644 --- a/src/libexpr/flake/flake.cc +++ b/src/libexpr/flake/flake.cc @@ -4,6 +4,7 @@ #include "eval-inline.hh" #include "store-api.hh" #include "fetchers/fetchers.hh" +#include "finally.hh" #include #include @@ -387,6 +388,8 @@ LockedFlake lockFlake( const InputPath & inputPathPrefix)> updateLocks; + std::vector parents; + updateLocks = [&]( const FlakeInputs & flakeInputs, const LockedInputs & oldLocks, @@ -506,6 +509,14 @@ LockedFlake lockFlake( flake. Also, unless we already have this flake in the top-level lock file, use this flake's own lock file. */ + + /* Guard against circular flake imports. */ + for (auto & parent : parents) + if (parent == input.ref) + throw Error("found circular import of flake '%s'", parent); + parents.push_back(input.ref); + Finally cleanup([&]() { parents.pop_back(); }); + updateLocks(inputFlake.inputs, oldLock != oldLocks.inputs.end() ? (const LockedInputs &) oldLock->second -- cgit v1.2.3