From 70b537244df3f83523e82629b3c8cc1b0dea9c55 Mon Sep 17 00:00:00 2001 From: atagen Date: Thu, 23 Apr 2026 22:28:21 +1000 Subject: [PATCH] split <2.34 code in cmake --- CMakeLists.txt | 5 +++++ scope.cc | 27 ++++++++++++++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a9dd81..8ad43d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/scope.cc b/scope.cc index 190c0f4..d01a828 100644 --- a/scope.cc +++ b/scope.cc @@ -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 + } +);