Detect circular flake imports

Fixes #2997.
This commit is contained in:
Eelco Dolstra 2020-02-02 13:14:34 +01:00
parent a9ebc3ea5d
commit af35b318f3
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -4,6 +4,7 @@
#include "eval-inline.hh"
#include "store-api.hh"
#include "fetchers/fetchers.hh"
#include "finally.hh"
#include <iostream>
#include <ctime>
@ -387,6 +388,8 @@ LockedFlake lockFlake(
const InputPath & inputPathPrefix)>
updateLocks;
std::vector<FlakeRef> 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