From 07bffe799853ef5e2757b9892e4e3dac89bfccbb Mon Sep 17 00:00:00 2001 From: Alexander Bantyev Date: Wed, 10 Nov 2021 14:56:22 +0300 Subject: [PATCH] Flakes: refetch the input when a follows disappears When an input follows disappears, we can't just reuse the old lock file entries since we may be missing some required ones. Refetch the input when this happens. Closes https://github.com/NixOS/nix/issues/5289 --- src/libexpr/flake/flake.cc | 14 ++++++++++++++ tests/flakes.sh | 28 +++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/libexpr/flake/flake.cc b/src/libexpr/flake/flake.cc index 07ed3caa2..1dc6f5694 100644 --- a/src/libexpr/flake/flake.cc +++ b/src/libexpr/flake/flake.cc @@ -462,6 +462,8 @@ LockedFlake lockFlake( those. */ FlakeInputs fakeInputs; + bool refetch = false; + for (auto & i : oldLock->inputs) { if (auto lockedNode = std::get_if<0>(&i.second)) { fakeInputs.emplace(i.first, FlakeInput { @@ -469,12 +471,24 @@ LockedFlake lockFlake( .isFlake = (*lockedNode)->isFlake, }); } else if (auto follows = std::get_if<1>(&i.second)) { + auto o = input.overrides.find(i.first); + // If the override disappeared, we have to refetch the flake, + // since some of the inputs may not be present in the lockfile. + if (o == input.overrides.end()) { + refetch = true; + // There's no point populating the rest of the fake inputs, + // since we'll refetch the flake anyways. + break; + } fakeInputs.emplace(i.first, FlakeInput { .follows = *follows, }); } } + if (refetch) + fakeInputs = getFlake(state, oldLock->lockedRef, false, flakeCache).inputs; + computeLocks(fakeInputs, childNode, inputPath, oldLock, parent, parentPath); } diff --git a/tests/flakes.sh b/tests/flakes.sh index 57d1b9aad..9e10322b9 100644 --- a/tests/flakes.sh +++ b/tests/flakes.sh @@ -707,10 +707,10 @@ cat > $flakeFollowsA/flake.nix < $flakeFollowsB/flake.nix < $flakeFollowsC/flake.nix < $flakeFollowsA/flake.nix < $flakeFollowsA/flake.nix <