200 lines
6.4 KiB
Diff
200 lines
6.4 KiB
Diff
From d9e022548aff94e90914baa921ddb4cd939c0e5c Mon Sep 17 00:00:00 2001
|
|
From: xenia <xenia@awoo.systems>
|
|
Date: Sat, 21 Dec 2024 15:33:10 -0500
|
|
Subject: [PATCH] implement lix support
|
|
|
|
---
|
|
CMakeLists.txt | 27 ------------
|
|
extra-builtins.cc | 91 ++++++++++++++++-------------------------
|
|
meson.build | 18 ++++++++
|
|
nix-plugins-config.h.in | 3 --
|
|
4 files changed, 53 insertions(+), 86 deletions(-)
|
|
delete mode 100644 CMakeLists.txt
|
|
create mode 100644 meson.build
|
|
delete mode 100644 nix-plugins-config.h.in
|
|
|
|
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
|
deleted file mode 100644
|
|
index 9674fe8..0000000
|
|
--- a/CMakeLists.txt
|
|
+++ /dev/null
|
|
@@ -1,27 +0,0 @@
|
|
-cmake_minimum_required (VERSION 3.9)
|
|
-project (nix-plugins)
|
|
-set (nix-plugins_VERSION_MAJOR 15)
|
|
-set (nix-plugins_VERSION_MINOR 0)
|
|
-set (nix-plugins_VERSION_PATCH 0)
|
|
-
|
|
-find_package(PkgConfig)
|
|
-
|
|
-pkg_check_modules(NIX REQUIRED nix-expr>=2.24 nix-main>=2.24 nix-store>=2.24)
|
|
-
|
|
-find_path(BOOST_INCLUDE_DIR boost/format.hpp)
|
|
-if(BOOST_INCLUDE_DIR STREQUAL "BOOST_INCLUDE_DIR-NOTFOUND")
|
|
- message(FATAL_ERROR "Could not find Boost formatting library.")
|
|
-endif()
|
|
-include_directories(${BOOST_INCLUDE_DIR})
|
|
-
|
|
-if(APPLE)
|
|
- set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -flat_namespace -undefined suppress")
|
|
-endif()
|
|
-
|
|
-add_library(nix-extra-builtins MODULE extra-builtins.cc)
|
|
-configure_file(nix-plugins-config.h.in nix-plugins-config.h)
|
|
-target_include_directories(nix-extra-builtins PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
|
-target_include_directories(nix-extra-builtins PUBLIC ${NIX_INCLUDE_DIRS})
|
|
-target_compile_options(nix-extra-builtins PUBLIC ${NIX_CFLAGS_OTHER})
|
|
-
|
|
-install(TARGETS nix-extra-builtins DESTINATION lib/nix/plugins)
|
|
diff --git a/extra-builtins.cc b/extra-builtins.cc
|
|
index 3a0f90e..95aef5e 100644
|
|
--- a/extra-builtins.cc
|
|
+++ b/extra-builtins.cc
|
|
@@ -1,12 +1,8 @@
|
|
-#include <config.h>
|
|
-#include <primops.hh>
|
|
-#include <globals.hh>
|
|
-#include <config-global.hh>
|
|
-#include <eval-settings.hh>
|
|
-#include <common-eval-args.hh>
|
|
-#include <filtering-source-accessor.hh>
|
|
-
|
|
-#include "nix-plugins-config.h"
|
|
+#include <lix/config.h>
|
|
+#include <lix/libexpr/primops.hh>
|
|
+#include <lix/libstore/globals.hh>
|
|
+#include <lix/libexpr/eval-settings.hh>
|
|
+#include <lix/libcmd/common-eval-args.hh>
|
|
|
|
using namespace nix;
|
|
|
|
@@ -21,42 +17,41 @@ static ExtraBuiltinsSettings extraBuiltinsSettings;
|
|
|
|
static GlobalConfig::Register rp(&extraBuiltinsSettings);
|
|
|
|
-static void extraBuiltins(EvalState & state, const PosIdx pos,
|
|
+static void extraBuiltins(EvalState & state,
|
|
Value ** _args, Value & v)
|
|
{
|
|
- static auto extraBuiltinsFile = state.rootPath(CanonPath(extraBuiltinsSettings.extraBuiltinsFile.to_string()));
|
|
- if (auto rootFS2 = state.rootFS.dynamic_pointer_cast<AllowListSourceAccessor>())
|
|
- rootFS2->allowPrefix(CanonPath(extraBuiltinsFile.path.abs()));
|
|
+ static auto extraBuiltinsFile =
|
|
+ SourcePath(CanonPath(extraBuiltinsSettings.extraBuiltinsFile.to_string()));
|
|
|
|
try {
|
|
- auto fun = state.allocValue();
|
|
- state.evalFile(extraBuiltinsFile, *fun);
|
|
- Value * arg;
|
|
- if (evalSettings.enableNativeCode) {
|
|
- arg = state.baseEnv.values[0];
|
|
- } else {
|
|
- auto attrs = state.buildBindings(2);
|
|
-
|
|
- auto sExec = state.symbols.create("exec");
|
|
- attrs.alloc(sExec).mkPrimOp(new PrimOp {
|
|
- .name = "exec",
|
|
- .arity = 1,
|
|
- .fun = prim_exec,
|
|
- });
|
|
-
|
|
- auto sImportNative = state.symbols.create("importNative");
|
|
- attrs.alloc(sImportNative).mkPrimOp(new PrimOp {
|
|
- .name = "importNative",
|
|
- .arity = 2,
|
|
- .fun = prim_importNative,
|
|
- });
|
|
-
|
|
- arg = state.allocValue();
|
|
- arg->mkAttrs(attrs);
|
|
- }
|
|
+ auto fun = state.ctx.mem.allocValue();
|
|
+
|
|
+ // bypass the source path checking by directly reading and evaluating the file
|
|
+ // this also bypasses the eval cache but oh well
|
|
+ Expr& e = state.ctx.parseExprFromFile(extraBuiltinsFile.unsafeIntoChecked());
|
|
+ state.eval(e, *fun);
|
|
+
|
|
+ auto attrs = state.ctx.buildBindings(2);
|
|
+
|
|
+ auto sExec = state.ctx.symbols.create("exec");
|
|
+ attrs.alloc(sExec).mkPrimOp(new PrimOp {
|
|
+ .name = "exec",
|
|
+ .arity = 1,
|
|
+ .fun = prim_exec,
|
|
+ });
|
|
+
|
|
+ auto sImportNative = state.ctx.symbols.create("importNative");
|
|
+ attrs.alloc(sImportNative).mkPrimOp(new PrimOp {
|
|
+ .name = "importNative",
|
|
+ .arity = 2,
|
|
+ .fun = prim_importNative,
|
|
+ });
|
|
+
|
|
+ Value* arg = state.ctx.mem.allocValue();
|
|
+ arg->mkAttrs(attrs);
|
|
v.mkApp(fun, arg);
|
|
- state.forceValue(v, pos);
|
|
- } catch (FileNotFound &) {
|
|
+ state.forceValue(v, noPos);
|
|
+ } catch (SysError &) {
|
|
v.mkNull();
|
|
}
|
|
}
|
|
@@ -66,19 +61,3 @@ static RegisterPrimOp rp1({
|
|
.arity = 0,
|
|
.fun = extraBuiltins,
|
|
});
|
|
-
|
|
-static void cflags(EvalState & state, const PosIdx _pos,
|
|
- Value ** _args, Value & v)
|
|
-{
|
|
- auto attrs = state.buildBindings(3);
|
|
- attrs.alloc("NIX_INCLUDE_DIRS").mkString(NIX_INCLUDE_DIRS);
|
|
- attrs.alloc("NIX_CFLAGS_OTHER").mkString(NIX_CFLAGS_OTHER);
|
|
- attrs.alloc("BOOST_INCLUDE_DIR").mkString(BOOST_INCLUDE_DIR);
|
|
- v.mkAttrs(attrs);
|
|
-}
|
|
-
|
|
-static RegisterPrimOp rp2({
|
|
- .name = "__nix-cflags",
|
|
- .arity = 0,
|
|
- .fun = cflags,
|
|
-});
|
|
diff --git a/meson.build b/meson.build
|
|
new file mode 100644
|
|
index 0000000..0be6ce6
|
|
--- /dev/null
|
|
+++ b/meson.build
|
|
@@ -0,0 +1,18 @@
|
|
+project('lix-plugins',
|
|
+ ['c', 'cpp'],
|
|
+ default_options: ['cpp_std=gnu++20'],
|
|
+ version: '15.0.0')
|
|
+
|
|
+cpp = meson.get_compiler('cpp')
|
|
+pkgconfig = import('pkgconfig')
|
|
+
|
|
+lix_expr = dependency('lix-expr', version: '>=2.91')
|
|
+lix_store = dependency('lix-store', version: '>=2.91')
|
|
+lix_cmd = dependency('lix-cmd', version: '>=2.91')
|
|
+lix_main = dependency('lix-main', version: '>=2.91')
|
|
+boost = dependency('boost')
|
|
+
|
|
+library('lix-plugins',
|
|
+ 'extra-builtins.cc',
|
|
+ dependencies: [lix_expr, lix_store, lix_cmd, lix_main, boost],
|
|
+ install: true)
|
|
diff --git a/nix-plugins-config.h.in b/nix-plugins-config.h.in
|
|
deleted file mode 100644
|
|
index 459fea8..0000000
|
|
--- a/nix-plugins-config.h.in
|
|
+++ /dev/null
|
|
@@ -1,3 +0,0 @@
|
|
-#define NIX_INCLUDE_DIRS "@NIX_INCLUDE_DIRS@"
|
|
-#define NIX_CFLAGS_OTHER "@NIX_CFLAGS_OTHER@"
|
|
-#define BOOST_INCLUDE_DIR "@BOOST_INCLUDE_DIR@"
|
|
--
|
|
2.49.0
|
|
|