153 lines
4.9 KiB
Diff
153 lines
4.9 KiB
Diff
From 5e42fc10f1e0b276fc32600dcab7cd560cc3e00f 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 | 34 +++++++++-------------------------
|
|
meson.build | 18 ++++++++++++++++++
|
|
nix-plugins-config.h.in | 3 ---
|
|
4 files changed, 27 insertions(+), 55 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..03947ef 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"
|
|
|
|
using namespace nix;
|
|
|
|
@@ -24,13 +20,17 @@ static GlobalConfig::Register rp(&extraBuiltinsSettings);
|
|
static void extraBuiltins(EvalState & state, const PosIdx pos,
|
|
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 = state.rootPath(
|
|
+ CanonPath(extraBuiltinsSettings.extraBuiltinsFile.to_string()));
|
|
|
|
try {
|
|
auto fun = state.allocValue();
|
|
- state.evalFile(extraBuiltinsFile, *fun);
|
|
+
|
|
+ // bypass the source path checking by directly reading and evaluating the file
|
|
+ // this also bypasses the eval cache but oh well
|
|
+ Expr& e = state.parseExprFromFile(extraBuiltinsFile);
|
|
+ state.eval(e, *fun);
|
|
+
|
|
Value * arg;
|
|
if (evalSettings.enableNativeCode) {
|
|
arg = state.baseEnv.values[0];
|
|
@@ -56,7 +56,7 @@ static void extraBuiltins(EvalState & state, const PosIdx pos,
|
|
}
|
|
v.mkApp(fun, arg);
|
|
state.forceValue(v, pos);
|
|
- } catch (FileNotFound &) {
|
|
+ } catch (SysError &) {
|
|
v.mkNull();
|
|
}
|
|
}
|
|
@@ -66,19 +66,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.47.0
|
|
|