From b2708694664f41f85ffc8cb6ca51cd0cc599806e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 2 Feb 2020 00:05:53 +0100 Subject: [PATCH] Renamed ref / resolvedRef -> lockedRef --- src/libexpr/flake/flake.cc | 60 +++++++++++++++++------------------ src/libexpr/flake/flake.hh | 2 +- src/libexpr/flake/lockfile.cc | 14 ++++---- src/libexpr/flake/lockfile.hh | 8 ++--- src/nix/flake.cc | 14 ++++---- src/nix/installables.cc | 4 +-- tests/flakes.sh | 20 ++++++------ 7 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/libexpr/flake/flake.cc b/src/libexpr/flake/flake.cc index 27e390fcd..37b6f6c2c 100644 --- a/src/libexpr/flake/flake.cc +++ b/src/libexpr/flake/flake.cc @@ -152,31 +152,31 @@ static Flake getFlake(EvalState & state, const FlakeRef & originalRef, auto [sourceInfo, resolvedInput] = flakeRef.input->fetchTree(state.store); - FlakeRef resolvedRef(resolvedInput, flakeRef.subdir); + FlakeRef lockedRef(resolvedInput, flakeRef.subdir); debug("got flake source '%s' from '%s'", - state.store->printStorePath(sourceInfo.storePath), resolvedRef); + state.store->printStorePath(sourceInfo.storePath), lockedRef); - flakeCache.push_back({originalRef, resolvedRef}); - flakeCache.push_back({flakeRef, resolvedRef}); + flakeCache.push_back({originalRef, lockedRef}); + flakeCache.push_back({flakeRef, lockedRef}); if (state.allowedPaths) state.allowedPaths->insert(sourceInfo.actualPath); // Guard against symlink attacks. - auto flakeFile = canonPath(sourceInfo.actualPath + "/" + resolvedRef.subdir + "/flake.nix"); + auto flakeFile = canonPath(sourceInfo.actualPath + "/" + lockedRef.subdir + "/flake.nix"); if (!isInDir(flakeFile, sourceInfo.actualPath)) throw Error("'flake.nix' file of flake '%s' escapes from '%s'", - resolvedRef, state.store->printStorePath(sourceInfo.storePath)); + lockedRef, state.store->printStorePath(sourceInfo.storePath)); Flake flake { .originalRef = originalRef, - .resolvedRef = resolvedRef, + .lockedRef = lockedRef, .sourceInfo = std::make_shared(std::move(sourceInfo)) }; if (!pathExists(flakeFile)) - throw Error("source tree referenced by '%s' does not contain a '%s/flake.nix' file", resolvedRef, resolvedRef.subdir); + throw Error("source tree referenced by '%s' does not contain a '%s/flake.nix' file", lockedRef, lockedRef.subdir); Value vInfo; state.evalFile(flakeFile, vInfo, true); // FIXME: symlink attack @@ -259,18 +259,18 @@ static std::pair getNonFlake( auto [sourceInfo, resolvedInput] = flakeRef.input->fetchTree(state.store); - FlakeRef resolvedRef(resolvedInput, flakeRef.subdir); + FlakeRef lockedRef(resolvedInput, flakeRef.subdir); debug("got non-flake source '%s' from '%s'", - state.store->printStorePath(sourceInfo.storePath), resolvedRef); + state.store->printStorePath(sourceInfo.storePath), lockedRef); - flakeCache.push_back({originalRef, resolvedRef}); - flakeCache.push_back({flakeRef, resolvedRef}); + flakeCache.push_back({originalRef, lockedRef}); + flakeCache.push_back({flakeRef, lockedRef}); if (state.allowedPaths) state.allowedPaths->insert(sourceInfo.actualPath); - return std::make_pair(std::move(sourceInfo), resolvedRef); + return std::make_pair(std::move(sourceInfo), lockedRef); } static void flattenLockFile( @@ -298,18 +298,18 @@ static std::string diffLockFiles(const LockedInputs & oldLocks, const LockedInpu while (i != oldFlat.end() || j != newFlat.end()) { if (j != newFlat.end() && (i == oldFlat.end() || i->first > j->first)) { - res += fmt(" added '%s': '%s'\n", concatStringsSep("/", j->first), j->second->ref); + res += fmt(" added '%s': '%s'\n", concatStringsSep("/", j->first), j->second->lockedRef); ++j; } else if (i != oldFlat.end() && (j == newFlat.end() || i->first < j->first)) { res += fmt(" removed '%s'\n", concatStringsSep("/", i->first)); ++i; } else { - if (!(i->second->ref == j->second->ref)) { - assert(i->second->ref.to_string() != j->second->ref.to_string()); + if (!(i->second->lockedRef == j->second->lockedRef)) { + assert(i->second->lockedRef.to_string() != j->second->lockedRef.to_string()); res += fmt(" updated '%s': '%s' -> '%s'\n", concatStringsSep("/", i->first), - i->second->ref, - j->second->ref); + i->second->lockedRef, + j->second->lockedRef); } ++i; ++j; @@ -337,7 +337,7 @@ LockedFlake lockFlake( if (!lockFlags.recreateLockFile) { // FIXME: symlink attack oldLockFile = LockFile::read( - flake.sourceInfo->actualPath + "/" + flake.resolvedRef.subdir + "/flake.lock"); + flake.sourceInfo->actualPath + "/" + flake.lockedRef.subdir + "/flake.lock"); } debug("old lock file: %s", oldLockFile); @@ -443,7 +443,7 @@ LockedFlake lockFlake( && std::equal(inputPath.begin(), inputPath.end(), lb->begin()); if (hasChildUpdate) { - auto inputFlake = getFlake(state, oldLock->second.ref, false, flakeCache); + auto inputFlake = getFlake(state, oldLock->second.lockedRef, false, flakeCache); updateLocks(inputFlake.inputs, (const LockedInputs &) oldLock->second, @@ -478,7 +478,7 @@ LockedFlake lockFlake( lockFlags.useRegistries, flakeCache); newLocks.inputs.insert_or_assign(id, - LockedInput(inputFlake.resolvedRef, inputFlake.originalRef, inputFlake.sourceInfo->info)); + LockedInput(inputFlake.lockedRef, inputFlake.originalRef, inputFlake.sourceInfo->info)); /* Recursively process the inputs of this flake. Also, unless we already have this @@ -488,16 +488,16 @@ LockedFlake lockFlake( oldLock != oldLocks.inputs.end() ? (const LockedInputs &) oldLock->second : LockFile::read( - inputFlake.sourceInfo->actualPath + "/" + inputFlake.resolvedRef.subdir + "/flake.lock"), + inputFlake.sourceInfo->actualPath + "/" + inputFlake.lockedRef.subdir + "/flake.lock"), newLocks.inputs.find(id)->second, inputPath); } else { - auto [sourceInfo, resolvedRef] = getNonFlake(state, input.ref, + auto [sourceInfo, lockedRef] = getNonFlake(state, input.ref, lockFlags.useRegistries, flakeCache); newLocks.inputs.insert_or_assign(id, - LockedInput(resolvedRef, input.ref, sourceInfo.info)); + LockedInput(lockedRef, input.ref, sourceInfo.info)); } } } @@ -606,11 +606,11 @@ static void prim_callFlake(EvalState & state, const Pos & pos, Value * * args, V auto lazyInput = (LazyInput *) args[0]->attrs; if (lazyInput->isFlake) { - auto flake = getFlake(state, lazyInput->lockedInput.ref, false); + auto flake = getFlake(state, lazyInput->lockedInput.lockedRef, false); if (flake.sourceInfo->info.narHash != lazyInput->lockedInput.info.narHash) throw Error("the content hash of flake '%s' (%s) doesn't match the hash recorded in the referring lock file (%s)", - lazyInput->lockedInput.ref, + lazyInput->lockedInput.lockedRef, flake.sourceInfo->info.narHash.to_string(SRI), lazyInput->lockedInput.info.narHash.to_string(SRI)); @@ -622,11 +622,11 @@ static void prim_callFlake(EvalState & state, const Pos & pos, Value * * args, V callFlake(state, flake, lazyInput->lockedInput, v); } else { FlakeCache flakeCache; - auto [sourceInfo, resolvedRef] = getNonFlake(state, lazyInput->lockedInput.ref, false, flakeCache); + auto [sourceInfo, lockedRef] = getNonFlake(state, lazyInput->lockedInput.lockedRef, false, flakeCache); if (sourceInfo.info.narHash != lazyInput->lockedInput.info.narHash) throw Error("the content hash of repository '%s' (%s) doesn't match the hash recorded in the referring lock file (%s)", - lazyInput->lockedInput.ref, + lazyInput->lockedInput.lockedRef, sourceInfo.info.narHash.to_string(SRI), lazyInput->lockedInput.info.narHash.to_string(SRI)); @@ -643,7 +643,7 @@ static void prim_callFlake(EvalState & state, const Pos & pos, Value * * args, V mkString(*state.allocAttr(v, state.sOutPath), pathS, {pathS}); - emitSourceInfoAttrs(state, resolvedRef, sourceInfo, v); + emitSourceInfoAttrs(state, lockedRef, sourceInfo, v); v.attrs->sort(); } @@ -676,7 +676,7 @@ void callFlake(EvalState & state, auto & vSourceInfo = *state.allocValue(); state.mkAttrs(vSourceInfo, 8); - emitSourceInfoAttrs(state, flake.resolvedRef, *flake.sourceInfo, vSourceInfo); + emitSourceInfoAttrs(state, flake.lockedRef, *flake.sourceInfo, vSourceInfo); vSourceInfo.attrs->sort(); vInputs.attrs->push_back(Attr(state.sSelf, &vRes)); diff --git a/src/libexpr/flake/flake.hh b/src/libexpr/flake/flake.hh index fd03faf13..4eb36236c 100644 --- a/src/libexpr/flake/flake.hh +++ b/src/libexpr/flake/flake.hh @@ -28,7 +28,7 @@ struct FlakeInput struct Flake { FlakeRef originalRef; - FlakeRef resolvedRef; + FlakeRef lockedRef; std::optional description; std::shared_ptr sourceInfo; FlakeInputs inputs; diff --git a/src/libexpr/flake/lockfile.cc b/src/libexpr/flake/lockfile.cc index e2586ab93..9879ef2a7 100644 --- a/src/libexpr/flake/lockfile.cc +++ b/src/libexpr/flake/lockfile.cc @@ -80,12 +80,12 @@ static TreeInfo parseTreeInfo(const nlohmann::json & json) LockedInput::LockedInput(const nlohmann::json & json) : LockedInputs(json) - , ref(getFlakeRef(json, "url", "uri", "resolvedRef")) - , originalRef(getFlakeRef(json, "originalUrl", "originalUri", "originalRef")) + , lockedRef(getFlakeRef(json, "url", "uri", "locked")) + , originalRef(getFlakeRef(json, "originalUrl", "originalUri", "original")) , info(parseTreeInfo(json)) { - if (!ref.isImmutable()) - throw Error("lockfile contains mutable flakeref '%s'", ref); + if (!lockedRef.isImmutable()) + throw Error("lockfile contains mutable flakeref '%s'", lockedRef); } static nlohmann::json treeInfoToJson(const TreeInfo & info) @@ -103,8 +103,8 @@ static nlohmann::json treeInfoToJson(const TreeInfo & info) nlohmann::json LockedInput::toJson() const { auto json = LockedInputs::toJson(); - json["originalRef"] = fetchers::attrsToJson(originalRef.toAttrs()); - json["resolvedRef"] = fetchers::attrsToJson(ref.toAttrs()); + json["original"] = fetchers::attrsToJson(originalRef.toAttrs()); + json["locked"] = fetchers::attrsToJson(lockedRef.toAttrs()); json["info"] = treeInfoToJson(info); return json; } @@ -136,7 +136,7 @@ nlohmann::json LockedInputs::toJson() const bool LockedInputs::isImmutable() const { for (auto & i : inputs) - if (!i.second.ref.isImmutable() || !i.second.isImmutable()) return false; + if (!i.second.lockedRef.isImmutable() || !i.second.isImmutable()) return false; return true; } diff --git a/src/libexpr/flake/lockfile.hh b/src/libexpr/flake/lockfile.hh index d1cbf7c06..6333a6875 100644 --- a/src/libexpr/flake/lockfile.hh +++ b/src/libexpr/flake/lockfile.hh @@ -35,11 +35,11 @@ struct LockedInputs /* Lock file information about a flake input. */ struct LockedInput : LockedInputs { - FlakeRef ref, originalRef; + FlakeRef lockedRef, originalRef; TreeInfo info; - LockedInput(const FlakeRef & ref, const FlakeRef & originalRef, const TreeInfo & info) - : ref(ref), originalRef(originalRef), info(info) + LockedInput(const FlakeRef & lockedRef, const FlakeRef & originalRef, const TreeInfo & info) + : lockedRef(lockedRef), originalRef(originalRef), info(info) { } LockedInput(const nlohmann::json & json); @@ -47,7 +47,7 @@ struct LockedInput : LockedInputs bool operator ==(const LockedInput & other) const { return - ref == other.ref + lockedRef == other.lockedRef && originalRef == other.originalRef && info == other.info && inputs == other.inputs; diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 7924cec7c..3b473de73 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -79,12 +79,12 @@ struct CmdFlakeList : EvalCommand static void printFlakeInfo(const Store & store, const Flake & flake) { - std::cout << fmt("URL: %s\n", flake.resolvedRef.input->to_string()); + std::cout << fmt("URL: %s\n", flake.lockedRef.input->to_string()); std::cout << fmt("Edition: %s\n", flake.edition); if (flake.description) std::cout << fmt("Description: %s\n", *flake.description); std::cout << fmt("Path: %s\n", store.printStorePath(flake.sourceInfo->storePath)); - if (auto rev = flake.resolvedRef.input->getRev()) + if (auto rev = flake.lockedRef.input->getRev()) std::cout << fmt("Revision: %s\n", rev->to_string(Base16, false)); if (flake.sourceInfo->info.revCount) std::cout << fmt("Revisions: %s\n", *flake.sourceInfo->info.revCount); @@ -99,8 +99,8 @@ static nlohmann::json flakeToJson(const Store & store, const Flake & flake) if (flake.description) j["description"] = *flake.description; j["edition"] = flake.edition; - j["url"] = flake.resolvedRef.input->to_string(); - if (auto rev = flake.resolvedRef.input->getRev()) + j["url"] = flake.lockedRef.input->to_string(); + if (auto rev = flake.lockedRef.input->getRev()) j["revision"] = rev->to_string(Base16, false); if (flake.sourceInfo->info.revCount) j["revCount"] = *flake.sourceInfo->info.revCount; @@ -201,7 +201,7 @@ struct CmdFlakeListInputs : FlakeCommand, MixJSON if (json) std::cout << ((LockedInputs &) flake.lockFile).toJson() << "\n"; else { - std::cout << fmt("%s\n", flake.flake.resolvedRef); + std::cout << fmt("%s\n", flake.flake.lockedRef); std::function recurse; @@ -211,7 +211,7 @@ struct CmdFlakeListInputs : FlakeCommand, MixJSON //auto tree2 = tree.child(i + 1 == inputs.inputs.size()); bool last = i + 1 == inputs.inputs.size(); std::cout << fmt("%s" ANSI_BOLD "%s" ANSI_NORMAL ": %s\n", - prefix + (last ? treeLast : treeConn), input.first, input.second.ref); + prefix + (last ? treeLast : treeConn), input.first, input.second.lockedRef); recurse(input.second, prefix + (last ? treeNull : treeLine)); } }; @@ -667,7 +667,7 @@ struct CmdFlakeArchive : FlakeCommand, MixJSON, MixDryRun for (auto & input : inputs.inputs) { auto jsonObj3 = jsonObj2 ? jsonObj2->object(input.first) : std::optional(); if (!dryRun) - input.second.ref.input->fetchTree(store); + input.second.lockedRef.input->fetchTree(store); auto storePath = input.second.computeStorePath(*store); if (jsonObj3) jsonObj3->attr("path", store->printStorePath(storePath)); diff --git a/src/nix/installables.cc b/src/nix/installables.cc index cf91be51b..545b5e839 100644 --- a/src/nix/installables.cc +++ b/src/nix/installables.cc @@ -348,7 +348,7 @@ std::tuple InstallableFlake auto drv = evalCache.getDerivation(fingerprint, attrPath); if (drv) { if (state->store->isValidPath(drv->drvPath)) - return {attrPath, lockedFlake.flake.resolvedRef, std::move(*drv)}; + return {attrPath, lockedFlake.flake.lockedRef, std::move(*drv)}; } if (!vOutputs) @@ -370,7 +370,7 @@ std::tuple InstallableFlake evalCache.addDerivation(fingerprint, attrPath, drv); - return {attrPath, lockedFlake.flake.resolvedRef, std::move(drv)}; + return {attrPath, lockedFlake.flake.lockedRef, std::move(drv)}; } catch (AttrPathNotFound & e) { } } diff --git a/tests/flakes.sh b/tests/flakes.sh index 57081f72f..141bb9779 100644 --- a/tests/flakes.sh +++ b/tests/flakes.sh @@ -480,7 +480,7 @@ cat > $flake3Dir/flake.nix < $flake3Dir/flake.nix < $flake3Dir/flake.nix < $flake3Dir/flake.nix < $flake3Dir/flake.nix < $flake3Dir/flake.nix < $flake3Dir/flake.nix < $flake3Dir/flake.nix < $flake3Dir/flake.nix <