Renamed ref / resolvedRef -> lockedRef

This commit is contained in:
Eelco Dolstra 2020-02-02 00:05:53 +01:00
parent 887730aab3
commit b270869466
No known key found for this signature in database
GPG Key ID: 8170B4726D7198DE
7 changed files with 61 additions and 61 deletions

View File

@ -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<fetchers::Tree>(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<fetchers::Tree, FlakeRef> 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));

View File

@ -28,7 +28,7 @@ struct FlakeInput
struct Flake
{
FlakeRef originalRef;
FlakeRef resolvedRef;
FlakeRef lockedRef;
std::optional<std::string> description;
std::shared_ptr<const fetchers::Tree> sourceInfo;
FlakeInputs inputs;

View File

@ -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;
}

View File

@ -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;

View File

@ -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<void(const LockedInputs & inputs, const std::string & prefix)> 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<JSONObject>();
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));

View File

@ -348,7 +348,7 @@ std::tuple<std::string, FlakeRef, flake::EvalCache::Derivation> 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<std::string, FlakeRef, flake::EvalCache::Derivation> 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) {
}
}

View File

@ -480,7 +480,7 @@ cat > $flake3Dir/flake.nix <<EOF
EOF
nix flake update $flake3Dir
[[ $(jq .inputs.foo.resolvedRef $flake3Dir/flake.lock) = $(jq .inputs.bar.resolvedRef $flake3Dir/flake.lock) ]]
[[ $(jq .inputs.foo.locked $flake3Dir/flake.lock) = $(jq .inputs.bar.locked $flake3Dir/flake.lock) ]]
cat > $flake3Dir/flake.nix <<EOF
{
@ -494,7 +494,7 @@ cat > $flake3Dir/flake.nix <<EOF
EOF
nix flake update $flake3Dir
[[ $(jq .inputs.bar.resolvedRef.url $flake3Dir/flake.lock) =~ flake1 ]]
[[ $(jq .inputs.bar.locked.url $flake3Dir/flake.lock) =~ flake1 ]]
cat > $flake3Dir/flake.nix <<EOF
{
@ -508,7 +508,7 @@ cat > $flake3Dir/flake.nix <<EOF
EOF
nix flake update $flake3Dir
[[ $(jq .inputs.bar.resolvedRef.url $flake3Dir/flake.lock) =~ flake2 ]]
[[ $(jq .inputs.bar.locked.url $flake3Dir/flake.lock) =~ flake2 ]]
# Test overriding inputs of inputs.
cat > $flake3Dir/flake.nix <<EOF
@ -523,7 +523,7 @@ cat > $flake3Dir/flake.nix <<EOF
EOF
nix flake update $flake3Dir
[[ $(jq .inputs.flake2.inputs.flake1.resolvedRef.url $flake3Dir/flake.lock) =~ flake7 ]]
[[ $(jq .inputs.flake2.inputs.flake1.locked.url $flake3Dir/flake.lock) =~ flake7 ]]
cat > $flake3Dir/flake.nix <<EOF
{
@ -538,7 +538,7 @@ cat > $flake3Dir/flake.nix <<EOF
EOF
nix flake update $flake3Dir --recreate-lock-file
[[ $(jq .inputs.flake2.inputs.flake1.resolvedRef.url $flake3Dir/flake.lock) =~ flake7 ]]
[[ $(jq .inputs.flake2.inputs.flake1.locked.url $flake3Dir/flake.lock) =~ flake7 ]]
# Test Mercurial flakes.
if [[ -z $(type -p hg) ]]; then
@ -605,20 +605,20 @@ nix build -o $TEST_ROOT/result "file://$TEST_ROOT/flake.tar.gz?narHash=sha256-qQ
# Test --override-input.
git -C $flake3Dir reset --hard
nix flake update $flake3Dir --override-input flake2/flake1 flake5
[[ $(jq .inputs.flake2.inputs.flake1.resolvedRef.url $flake3Dir/flake.lock) =~ flake5 ]]
[[ $(jq .inputs.flake2.inputs.flake1.locked.url $flake3Dir/flake.lock) =~ flake5 ]]
nix flake update $flake3Dir --override-input flake2/flake1 flake1
[[ $(jq -r .inputs.flake2.inputs.flake1.resolvedRef.rev $flake3Dir/flake.lock) =~ $hash2 ]]
[[ $(jq -r .inputs.flake2.inputs.flake1.locked.rev $flake3Dir/flake.lock) =~ $hash2 ]]
nix flake update $flake3Dir --override-input flake2/flake1 flake1/master/$hash1
[[ $(jq -r .inputs.flake2.inputs.flake1.resolvedRef.rev $flake3Dir/flake.lock) =~ $hash1 ]]
[[ $(jq -r .inputs.flake2.inputs.flake1.locked.rev $flake3Dir/flake.lock) =~ $hash1 ]]
# Test --update-input.
nix flake update $flake3Dir
[[ $(jq -r .inputs.flake2.inputs.flake1.resolvedRef.rev $flake3Dir/flake.lock) = $hash1 ]]
[[ $(jq -r .inputs.flake2.inputs.flake1.locked.rev $flake3Dir/flake.lock) = $hash1 ]]
nix flake update $flake3Dir --update-input flake2/flake1
[[ $(jq -r .inputs.flake2.inputs.flake1.resolvedRef.rev $flake3Dir/flake.lock) =~ $hash2 ]]
[[ $(jq -r .inputs.flake2.inputs.flake1.locked.rev $flake3Dir/flake.lock) =~ $hash2 ]]
# Test 'nix flake list-inputs'.
[[ $(nix flake list-inputs $flake3Dir | wc -l) == 5 ]]