aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-05-22 18:49:12 +0200
committerGitHub <noreply@github.com>2019-05-22 18:49:12 +0200
commit55a0451e5132b460ec80eb30647c3d957fc1ce98 (patch)
tree100dd79f04efc04f3b139cf32eae10e6d3a51ac3 /src
parent7c7105e0f89fb7b0971fbe012296f811f245e798 (diff)
parente414bde6f9f58e599d48307ff3cb0ab64cb47d9a (diff)
Merge pull request #2884 from NixOS/check-epoch
Check the flake epoch
Diffstat (limited to 'src')
-rw-r--r--src/libexpr/primops/flake.cc11
-rw-r--r--src/libexpr/primops/flake.hh3
-rw-r--r--src/nix/flake.cc2
3 files changed, 13 insertions, 3 deletions
diff --git a/src/libexpr/primops/flake.cc b/src/libexpr/primops/flake.cc
index c08c30c9c..9131080bf 100644
--- a/src/libexpr/primops/flake.cc
+++ b/src/libexpr/primops/flake.cc
@@ -309,10 +309,17 @@ Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool impureIsAllowe
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))
flake.id = state.forceStringNoCtx(*(**name).value, *(**name).pos);
else
- throw Error("flake lacks attribute 'name'");
+ throw Error("flake '%s' lacks attribute 'name'", flakeRef);
if (auto description = vInfo.attrs->get(state.sDescription))
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);
flake.vProvides = (**provides).value;
} else
- throw Error("flake lacks attribute 'provides'");
+ throw Error("flake '%s' lacks attribute 'provides'", flakeRef);
return flake;
}
diff --git a/src/libexpr/primops/flake.hh b/src/libexpr/primops/flake.hh
index 8eaac9d96..983c0eab6 100644
--- a/src/libexpr/primops/flake.hh
+++ b/src/libexpr/primops/flake.hh
@@ -101,7 +101,8 @@ struct Flake
std::map<FlakeAlias, FlakeRef> nonFlakeRequires;
Value * vProvides; // FIXME: gc
// date
- // content hash
+ unsigned int epoch;
+
Flake(const FlakeRef & origRef, const SourceInfo & sourceInfo) : originalRef(origRef),
resolvedRef(sourceInfo.resolvedRef), revCount(sourceInfo.revCount), storePath(sourceInfo.storePath) {};
};
diff --git a/src/nix/flake.cc b/src/nix/flake.cc
index ecbb3b81f..2dcdfc663 100644
--- a/src/nix/flake.cc
+++ b/src/nix/flake.cc
@@ -83,6 +83,7 @@ void printFlakeInfo(const Flake & flake, bool json) {
if (flake.revCount)
j["revCount"] = *flake.revCount;
j["path"] = flake.storePath;
+ j["epoch"] = flake.epoch;
std::cout << j.dump(4) << std::endl;
} else {
std::cout << "ID: " << flake.id << "\n";
@@ -95,6 +96,7 @@ void printFlakeInfo(const Flake & flake, bool json) {
if (flake.revCount)
std::cout << "Revcount: " << *flake.revCount << "\n";
std::cout << "Path: " << flake.storePath << "\n";
+ std::cout << "Epoch: " << flake.epoch << "\n";
}
}