split <2.34 code in cmake

This commit is contained in:
atagen 2026-04-23 22:28:21 +10:00
parent df23fb0436
commit 70b537244d
2 changed files with 23 additions and 9 deletions

View file

@ -8,4 +8,9 @@ add_library(nix-scope-plugin MODULE scope.cc)
target_link_libraries(nix-scope-plugin PkgConfig::NIX_EXPR)
set_target_properties(nix-scope-plugin PROPERTIES PREFIX "lib")
if(NIX_EXPR_VERSION VERSION_LESS "2.34")
target_compile_definitions(nix-scope-plugin PRIVATE NIX_PRE_234)
endif()
message(STATUS "Building nix-scope-plugin against nix-expr ${NIX_EXPR_VERSION}")
install(TARGETS nix-scope-plugin DESTINATION lib/nix/plugins)

View file

@ -40,13 +40,22 @@ static void prim_scope(EvalState & state, const PosIdx pos, Value ** args, Value
v = *inner;
}
static RegisterPrimOp rp(PrimOp{
.name = "scope",
.args = {"path", "value"},
.doc = R"(
Construct a nested attribute set from a dotted string path and a value.
static RegisterPrimOp rp(
#ifndef NIX_PRE_234
PrimOp
#endif
{
.name = "scope",
.args = {"path", "value"},
.doc = R"(
Construct a nested attribute set from a dotted string path and a value.
Example: `scope "a.b.c" 42` evaluates to `{ a = { b = { c = 42; }; }; }`.
)",
.impl = prim_scope,
});
Example: `scope "a.b.c" 42` evaluates to `{ a = { b = { c = 42; }; }; }`.
)",
#ifdef NIX_PRE_234
.fun = prim_scope,
#else
.impl = prim_scope,
#endif
}
);