aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr
diff options
context:
space:
mode:
authorpiegames <git@piegames.de>2024-08-18 16:02:23 +0200
committerpiegames <git@piegames.de>2024-08-21 06:55:52 +0000
commit7210ed1b87410a0df597c0c4efe642bf82cc2b06 (patch)
tree85be2a9cc889c74da6a16dd8ca64713f86ce8691 /src/libexpr
parentac6974777efdaa85715cf7838fe878665061f86c (diff)
libexpr: Soft-deprecate __overrides
Change-Id: I787e69e1dad6edc5ccdb747b74a9ccd6e8e13bb3
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/eval.cc1
-rw-r--r--src/libexpr/nixexpr.hh2
-rw-r--r--src/libexpr/parser/parser.cc6
-rw-r--r--src/libexpr/parser/state.hh19
4 files changed, 27 insertions, 1 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index fcc28d1ca..227cd254a 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -249,6 +249,7 @@ EvalState::EvalState(
.findFile = symbols.create("__findFile"),
.nixPath = symbols.create("__nixPath"),
.body = symbols.create("body"),
+ .overrides = symbols.create("__overrides"),
}
, repair(NoRepair)
, emptyBindings(0)
diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh
index 49e2e4147..52f254813 100644
--- a/src/libexpr/nixexpr.hh
+++ b/src/libexpr/nixexpr.hh
@@ -48,7 +48,7 @@ protected:
public:
struct AstSymbols {
- Symbol sub, lessThan, mul, div, or_, findFile, nixPath, body;
+ Symbol sub, lessThan, mul, div, or_, findFile, nixPath, body, overrides;
};
diff --git a/src/libexpr/parser/parser.cc b/src/libexpr/parser/parser.cc
index d57c33a30..6e8ab2fe4 100644
--- a/src/libexpr/parser/parser.cc
+++ b/src/libexpr/parser/parser.cc
@@ -676,6 +676,12 @@ template<> struct BuildAST<grammar::expr::ancient_let> : change_head<BindingsSta
template<> struct BuildAST<grammar::expr::rec_set> : change_head<BindingsState> {
static void success(const auto & in, BindingsState & b, ExprState & s, State & ps) {
+ // Before inserting new attrs, check for __override and throw an error
+ // (the error will initially be a warning to ease migration)
+ if (!featureSettings.isEnabled(Dep::RecSetOverrides) && b.attrs.attrs.contains(ps.s.overrides)) {
+ ps.overridesFound(ps.at(in));
+ }
+
b.attrs.pos = ps.at(in);
b.attrs.recursive = true;
s.pushExpr<ExprAttrs>(b.attrs.pos, std::move(b.attrs));
diff --git a/src/libexpr/parser/state.hh b/src/libexpr/parser/state.hh
index 9dddd28e1..1d57e2f5f 100644
--- a/src/libexpr/parser/state.hh
+++ b/src/libexpr/parser/state.hh
@@ -2,6 +2,7 @@
///@file
#include "eval.hh"
+#include "logging.hh"
namespace nix::parser {
@@ -23,6 +24,7 @@ struct State
void dupAttr(const AttrPath & attrPath, const PosIdx pos, const PosIdx prevPos);
void dupAttr(Symbol attr, const PosIdx pos, const PosIdx prevPos);
+ void overridesFound(const PosIdx pos);
void addAttr(ExprAttrs * attrs, AttrPath && attrPath, std::unique_ptr<Expr> e, const PosIdx pos);
std::unique_ptr<Formals> validateFormals(std::unique_ptr<Formals> formals, PosIdx pos = noPos, Symbol arg = {});
std::unique_ptr<Expr> stripIndentation(const PosIdx pos,
@@ -58,6 +60,17 @@ inline void State::dupAttr(Symbol attr, const PosIdx pos, const PosIdx prevPos)
});
}
+inline void State::overridesFound(const PosIdx pos) {
+ // Added 2024-09-18. Turn into an error at some point in the future.
+ // See the documentation on deprecated features for more details.
+ warn(
+ "%s found at %s. This feature is deprecated and will be removed in the future. Use %s to silence this warning.",
+ "__overrides",
+ positions[pos],
+ "--extra-deprecated-features rec-set-overrides"
+ );
+}
+
inline void State::addAttr(ExprAttrs * attrs, AttrPath && attrPath, std::unique_ptr<Expr> e, const PosIdx pos)
{
AttrPath::iterator i;
@@ -123,6 +136,12 @@ inline void State::addAttr(ExprAttrs * attrs, AttrPath && attrPath, std::unique_
dupAttr(attrPath, pos, j->second.pos);
}
} else {
+ // Before inserting new attrs, check for __override and throw an error
+ // (the error will initially be a warning to ease migration)
+ if (attrs->recursive && !featureSettings.isEnabled(Dep::RecSetOverrides) && i->symbol == s.overrides) {
+ overridesFound(pos);
+ }
+
// This attr path is not defined. Let's create it.
e->setName(i->symbol);
attrs->attrs.emplace(std::piecewise_construct,