Merge pull request #2884 from NixOS/check-epoch

Check the flake epoch
This commit is contained in:
Eelco Dolstra 2019-05-22 18:49:12 +02:00 committed by GitHub
commit 55a0451e51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 4 deletions

View file

@ -309,10 +309,17 @@ Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool impureIsAllowe
state.forceAttrs(vInfo); state.forceAttrs(vInfo);
if (auto epoch = vInfo.attrs->get(state.symbols.create("epoch"))) {
flake.epoch = state.forceInt(*(**epoch).value, *(**epoch).pos);
if (flake.epoch > 2019)
throw Error("flake '%s' requires unsupported epoch %d; please upgrade Nix", flakeRef, flake.epoch);
} else
throw Error("flake '%s' lacks attribute 'epoch'", flakeRef);
if (auto name = vInfo.attrs->get(state.sName)) if (auto name = vInfo.attrs->get(state.sName))
flake.id = state.forceStringNoCtx(*(**name).value, *(**name).pos); flake.id = state.forceStringNoCtx(*(**name).value, *(**name).pos);
else else
throw Error("flake lacks attribute 'name'"); throw Error("flake '%s' lacks attribute 'name'", flakeRef);
if (auto description = vInfo.attrs->get(state.sDescription)) if (auto description = vInfo.attrs->get(state.sDescription))
flake.description = state.forceStringNoCtx(*(**description).value, *(**description).pos); flake.description = state.forceStringNoCtx(*(**description).value, *(**description).pos);
@ -337,7 +344,7 @@ Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool impureIsAllowe
state.forceFunction(*(**provides).value, *(**provides).pos); state.forceFunction(*(**provides).value, *(**provides).pos);
flake.vProvides = (**provides).value; flake.vProvides = (**provides).value;
} else } else
throw Error("flake lacks attribute 'provides'"); throw Error("flake '%s' lacks attribute 'provides'", flakeRef);
return flake; return flake;
} }

View file

@ -101,7 +101,8 @@ struct Flake
std::map<FlakeAlias, FlakeRef> nonFlakeRequires; std::map<FlakeAlias, FlakeRef> nonFlakeRequires;
Value * vProvides; // FIXME: gc Value * vProvides; // FIXME: gc
// date // date
// content hash unsigned int epoch;
Flake(const FlakeRef & origRef, const SourceInfo & sourceInfo) : originalRef(origRef), Flake(const FlakeRef & origRef, const SourceInfo & sourceInfo) : originalRef(origRef),
resolvedRef(sourceInfo.resolvedRef), revCount(sourceInfo.revCount), storePath(sourceInfo.storePath) {}; resolvedRef(sourceInfo.resolvedRef), revCount(sourceInfo.revCount), storePath(sourceInfo.storePath) {};
}; };

View file

@ -83,6 +83,7 @@ void printFlakeInfo(const Flake & flake, bool json) {
if (flake.revCount) if (flake.revCount)
j["revCount"] = *flake.revCount; j["revCount"] = *flake.revCount;
j["path"] = flake.storePath; j["path"] = flake.storePath;
j["epoch"] = flake.epoch;
std::cout << j.dump(4) << std::endl; std::cout << j.dump(4) << std::endl;
} else { } else {
std::cout << "ID: " << flake.id << "\n"; std::cout << "ID: " << flake.id << "\n";
@ -95,6 +96,7 @@ void printFlakeInfo(const Flake & flake, bool json) {
if (flake.revCount) if (flake.revCount)
std::cout << "Revcount: " << *flake.revCount << "\n"; std::cout << "Revcount: " << *flake.revCount << "\n";
std::cout << "Path: " << flake.storePath << "\n"; std::cout << "Path: " << flake.storePath << "\n";
std::cout << "Epoch: " << flake.epoch << "\n";
} }
} }

View file

@ -146,7 +146,7 @@ nix build -o $TEST_ROOT/result file://$flake2Dir:bar
# Test whether indirect dependencies work. # Test whether indirect dependencies work.
nix build -o $TEST_ROOT/result --flake-registry $registry $flake3Dir:xyzzy nix build -o $TEST_ROOT/result --flake-registry $registry $flake3Dir:xyzzy
# Add dependency to flake3 # Add dependency to flake3.
rm $flake3Dir/flake.nix rm $flake3Dir/flake.nix
cat > $flake3Dir/flake.nix <<EOF cat > $flake3Dir/flake.nix <<EOF
@ -174,3 +174,7 @@ nix build -o $TEST_ROOT/result --flake-registry $registry $flake3Dir:sth
# Check whether it saved the lockfile # Check whether it saved the lockfile
[[ ! (-z $(git -C $flake3Dir diff master)) ]] [[ ! (-z $(git -C $flake3Dir diff master)) ]]
# Unsupported epochs should be an error.
sed -i $flake3Dir/flake.nix -e s/2019/2030/
nix build -o $TEST_ROOT/result --flake-registry $registry $flake3Dir:sth 2>&1 | grep 'unsupported epoch'