Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nix
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 26f895a26d37
Choose a base ref
...
head repository: NixOS/nix
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 68e0ca608fa5
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Jan 29, 2020

  1. Revive the flake cache

    Not that it matters a lot anymore - we respect lock files of inputs
    now, so we're doing a lot fewer flake lookups.
    edolstra committed Jan 29, 2020
    Copy the full SHA
    68e0ca6 View commit details
Showing with 23 additions and 25 deletions.
  1. +23 −25 src/libexpr/flake/flake.cc
48 changes: 23 additions & 25 deletions src/libexpr/flake/flake.cc
Original file line number Diff line number Diff line change
@@ -31,22 +31,20 @@ static FlakeRef maybeLookupFlake(
return flakeRef;
}

typedef std::vector<std::pair<FlakeRef, FlakeRef>> RefMap;
typedef std::vector<std::pair<FlakeRef, FlakeRef>> FlakeCache;

static FlakeRef lookupInRefMap(
const RefMap & refMap,
static FlakeRef lookupInFlakeCache(
const FlakeCache & flakeCache,
const FlakeRef & flakeRef)
{
#if 0
// FIXME: inefficient.
for (auto & i : refMap) {
if (flakeRef.contains(i.first)) {
for (auto & i : flakeCache) {
if (flakeRef == i.first) {
debug("mapping '%s' to previously seen input '%s' -> '%s",
flakeRef, i.first, i.second);
return i.second;
}
}
#endif

return flakeRef;
}
@@ -122,11 +120,11 @@ static std::map<FlakeId, FlakeInput> parseFlakeInputs(
}

static Flake getFlake(EvalState & state, const FlakeRef & originalRef,
bool allowLookup, RefMap & refMap)
bool allowLookup, FlakeCache & flakeCache)
{
auto flakeRef = lookupInRefMap(refMap,
auto flakeRef = lookupInFlakeCache(flakeCache,
maybeLookupFlake(state,
lookupInRefMap(refMap, originalRef), allowLookup));
lookupInFlakeCache(flakeCache, originalRef), allowLookup));

auto [sourceInfo, resolvedInput] = flakeRef.input->fetchTree(state.store);

@@ -135,8 +133,8 @@ static Flake getFlake(EvalState & state, const FlakeRef & originalRef,
debug("got flake source '%s' from '%s'",
state.store->printStorePath(sourceInfo.storePath), resolvedRef);

refMap.push_back({originalRef, resolvedRef});
refMap.push_back({flakeRef, resolvedRef});
flakeCache.push_back({originalRef, resolvedRef});
flakeCache.push_back({flakeRef, resolvedRef});

if (state.allowedPaths)
state.allowedPaths->insert(sourceInfo.actualPath);
@@ -221,19 +219,19 @@ static Flake getFlake(EvalState & state, const FlakeRef & originalRef,

Flake getFlake(EvalState & state, const FlakeRef & originalRef, bool allowLookup)
{
RefMap refMap;
return getFlake(state, originalRef, allowLookup, refMap);
FlakeCache flakeCache;
return getFlake(state, originalRef, allowLookup, flakeCache);
}

static std::pair<fetchers::Tree, FlakeRef> getNonFlake(
EvalState & state,
const FlakeRef & originalRef,
bool allowLookup,
RefMap & refMap)
FlakeCache & flakeCache)
{
auto flakeRef = lookupInRefMap(refMap,
auto flakeRef = lookupInFlakeCache(flakeCache,
maybeLookupFlake(state,
lookupInRefMap(refMap, originalRef), allowLookup));
lookupInFlakeCache(flakeCache, originalRef), allowLookup));

auto [sourceInfo, resolvedInput] = flakeRef.input->fetchTree(state.store);

@@ -242,8 +240,8 @@ static std::pair<fetchers::Tree, FlakeRef> getNonFlake(
debug("got non-flake source '%s' from '%s'",
state.store->printStorePath(sourceInfo.storePath), resolvedRef);

refMap.push_back({originalRef, resolvedRef});
refMap.push_back({flakeRef, resolvedRef});
flakeCache.push_back({originalRef, resolvedRef});
flakeCache.push_back({flakeRef, resolvedRef});

if (state.allowedPaths)
state.allowedPaths->insert(sourceInfo.actualPath);
@@ -304,9 +302,9 @@ LockedFlake lockFlake(
{
settings.requireExperimentalFeature("flakes");

RefMap refMap;
FlakeCache flakeCache;

auto flake = getFlake(state, topRef, lockFlags.useRegistries, refMap);
auto flake = getFlake(state, topRef, lockFlags.useRegistries, flakeCache);

LockFile oldLockFile;

@@ -428,7 +426,7 @@ LockedFlake lockFlake(

if (input.isFlake) {
auto inputFlake = getFlake(state, input.ref,
lockFlags.useRegistries, refMap);
lockFlags.useRegistries, flakeCache);

newLocks.inputs.insert_or_assign(id,
LockedInput(inputFlake.resolvedRef, inputFlake.originalRef, inputFlake.sourceInfo->narHash));
@@ -448,7 +446,7 @@ LockedFlake lockFlake(

else {
auto [sourceInfo, resolvedRef] = getNonFlake(state, input.ref,
lockFlags.useRegistries, refMap);
lockFlags.useRegistries, flakeCache);
newLocks.inputs.insert_or_assign(id,
LockedInput(resolvedRef, input.ref, sourceInfo.narHash));
}
@@ -563,8 +561,8 @@ static void prim_callFlake(EvalState & state, const Pos & pos, Value * * args, V

callFlake(state, flake, lazyInput->lockedInput, v);
} else {
RefMap refMap;
auto [sourceInfo, resolvedRef] = getNonFlake(state, lazyInput->lockedInput.ref, false, refMap);
FlakeCache flakeCache;
auto [sourceInfo, resolvedRef] = getNonFlake(state, lazyInput->lockedInput.ref, false, flakeCache);

if (sourceInfo.narHash != lazyInput->lockedInput.narHash)
throw Error("the content hash of repository '%s' doesn't match the hash recorded in the referring lockfile",