From f11008307a8644255733c36fb0908d90637b7ec7 Mon Sep 17 00:00:00 2001 From: eljamm Date: Thu, 10 Sep 2026 14:20:35 +0200 Subject: [PATCH 1/2] zelph: init at 1.0.1 Assisted-by: nix-init Assisted-by: LLMs in patching `FetchContent` declarations and building janet from source --- .../zelph/0001-Use-system-dependencies.patch | 180 ++++++++++++++++++ pkgs/by-name/ze/zelph/package.nix | 84 ++++++++ 2 files changed, 264 insertions(+) create mode 100644 pkgs/by-name/ze/zelph/0001-Use-system-dependencies.patch create mode 100644 pkgs/by-name/ze/zelph/package.nix diff --git a/pkgs/by-name/ze/zelph/0001-Use-system-dependencies.patch b/pkgs/by-name/ze/zelph/0001-Use-system-dependencies.patch new file mode 100644 index 0000000000000..51aa0d6a41dbe --- /dev/null +++ b/pkgs/by-name/ze/zelph/0001-Use-system-dependencies.patch @@ -0,0 +1,180 @@ +--- + src/lib/CMakeLists.txt | 86 +++++++++-------------------------------- + src/test/CMakeLists.txt | 27 ++++++------- + 2 files changed, 30 insertions(+), 83 deletions(-) + +diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt +index a0b4253..4cb679c 100644 +--- a/src/lib/CMakeLists.txt ++++ b/src/lib/CMakeLists.txt +@@ -26,6 +26,8 @@ include(CheckCXXCompilerFlag) + include(FetchContent) + include(CheckIPOSupported) + ++find_package(PkgConfig REQUIRED) ++ + set(_ZELPH_USE_MIMALLOC_DEFAULT OFF) + if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND PROJECT_IS_TOP_LEVEL) + set(_ZELPH_USE_MIMALLOC_DEFAULT ON) +@@ -65,40 +67,21 @@ option(ZELPH_USE_MIMALLOC + # is linked in, the system package is not used and its version says + # nothing about this one. + if(ZELPH_USE_MIMALLOC AND CMAKE_SYSTEM_NAME STREQUAL "Linux") +- set(MI_BUILD_SHARED OFF CACHE BOOL "" FORCE) +- # Upstream wires mimalloc-obj-target to mimalloc-static, so the OBJECT +- # build needs the static one to exist even though only the object is +- # linked. See point 2 above for how it fails when this is OFF. +- set(MI_BUILD_STATIC ON CACHE BOOL "" FORCE) +- set(MI_BUILD_OBJECT ON CACHE BOOL "" FORCE) +- set(MI_BUILD_TESTS OFF CACHE BOOL "" FORCE) +- set(MI_OVERRIDE ON CACHE BOOL "" FORCE) +- +- FetchContent_Declare( +- mimalloc +- GIT_REPOSITORY https://github.com/microsoft/mimalloc.git +- GIT_TAG v3.4.5 +- SYSTEM +- ) +- FetchContent_MakeAvailable(mimalloc) ++ find_package(mimalloc REQUIRED) + + add_library(zelph_mimalloc_override INTERFACE) + target_link_libraries(zelph_mimalloc_override INTERFACE +- mimalloc-obj +- "$" ++ mimalloc-static + ) + endif() + +-FetchContent_Declare( +- janet +- GIT_REPOSITORY https://github.com/janet-lang/janet.git +- GIT_TAG v1.41.2 +- SYSTEM +- SOURCE_SUBDIR "" +-) +- +-FetchContent_MakeAvailable(janet) ++# Janet is built from source. JANET_SOURCE_DIR must be set via cmake flag. ++if(NOT DEFINED JANET_SOURCE_DIR) ++ message(FATAL_ERROR "JANET_SOURCE_DIR must be set to the Janet source directory") ++endif() ++set(janet_SOURCE_DIR "${JANET_SOURCE_DIR}") + ++if(NOT TARGET janet_lib) + if(EMSCRIPTEN) + # The Meson/ninja subprocess build cannot produce wasm objects. Instead, + # generate Janet's amalgamated source with the HOST toolchain (the +@@ -230,54 +213,23 @@ endian = 'little'\n" + endif () + endif () + +-FetchContent_Declare( +- unordered_dense +- GIT_REPOSITORY https://github.com/martinus/unordered_dense.git +- GIT_TAG v4.8.1 +- SYSTEM +-) +- +-FetchContent_MakeAvailable(unordered_dense) ++endif() ++find_package(unordered_dense REQUIRED) + + if(NOT ZELPH_WASM) +- FetchContent_Declare( +- bzip2 +- GIT_REPOSITORY https://gitlab.com/bzip2/bzip2.git +- GIT_TAG bzip2-1.0.8 +- SYSTEM +-) +- +- FetchContent_GetProperties(bzip2) +- if (NOT bzip2_POPULATED) +- FetchContent_Populate(bzip2) +- add_library(bz2 STATIC +- ${bzip2_SOURCE_DIR}/blocksort.c +- ${bzip2_SOURCE_DIR}/bzlib.c +- ${bzip2_SOURCE_DIR}/compress.c +- ${bzip2_SOURCE_DIR}/crctable.c +- ${bzip2_SOURCE_DIR}/decompress.c +- ${bzip2_SOURCE_DIR}/huffman.c +- ${bzip2_SOURCE_DIR}/randtable.c ++ find_library(BZ2_LIBRARY bz2 REQUIRED) ++ find_path(BZ2_INCLUDE_DIR bzlib.h REQUIRED) ++ add_library(bz2 STATIC IMPORTED) ++ set_target_properties(bz2 PROPERTIES ++ IMPORTED_LOCATION "${BZ2_LIBRARY}" ++ INTERFACE_INCLUDE_DIRECTORIES "${BZ2_INCLUDE_DIR}" + ) +- target_include_directories(bz2 PUBLIC ${bzip2_SOURCE_DIR}) +- if (MSVC) +- target_compile_definitions(bz2 PRIVATE _CRT_SECURE_NO_WARNINGS) +- endif () +- set_target_properties(bz2 PROPERTIES POSITION_INDEPENDENT_CODE ON) +- endif () + +- FetchContent_Declare( +- CapnProto +- GIT_REPOSITORY https://github.com/capnproto/capnproto.git +- GIT_TAG v1.4.0 +- SYSTEM +- ) ++ find_package(CapnProto REQUIRED) + + set(WITH_OPENSSL OFF CACHE BOOL "" FORCE) + set(BUILD_TESTING OFF CACHE BOOL "" FORCE) + +- FetchContent_MakeAvailable(CapnProto) +- + # Suppress all warnings from Cap'n Proto targets (third-party), including LTO + set(CAPNP_TARGETS + kj +diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt +index 9de7ccf..f915b4b 100644 +--- a/src/test/CMakeLists.txt ++++ b/src/test/CMakeLists.txt +@@ -27,22 +27,9 @@ include(FetchContent) + # which newer CMake rejects. Allow it to configure anyway. + set(CMAKE_POLICY_VERSION_MINIMUM 3.5 CACHE STRING "") + +-FetchContent_Declare( +- doctest +- GIT_REPOSITORY https://github.com/doctest/doctest.git +- GIT_TAG v2.5.2 +- SYSTEM +-) +-FetchContent_MakeAvailable(doctest) +- +-FetchContent_Declare( +- unordered_dense +- GIT_REPOSITORY https://github.com/martinus/unordered_dense.git +- GIT_TAG v4.8.1 +- SYSTEM +-) ++find_package(doctest REQUIRED) + +-FetchContent_MakeAvailable(unordered_dense) ++find_package(unordered_dense REQUIRED) + + add_executable(zelph_tests + test_bin_inspection.cpp +@@ -111,7 +98,15 @@ add_executable(zelph_tests + test_wikidata_import.cpp + test_wikidata_qualifiers.cpp + ) +-target_link_libraries(zelph_tests PRIVATE zelph_lib doctest_with_main unordered_dense::unordered_dense) ++ ++# Generate a single translation unit that provides the doctest implementation. ++# Using DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN as a compile definition on the whole ++# target causes every TU to emit its own copy of main() and doctest internals. ++file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/doctest_main.cpp ++ "#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN\n#include \n") ++target_sources(zelph_tests PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/doctest_main.cpp) ++ ++target_link_libraries(zelph_tests PRIVATE zelph_lib doctest::doctest unordered_dense::unordered_dense) + + # Where test_paper_scripts.cpp looks. An absolute path into the SOURCE tree, + # because the scripts are development material and are not installed anywhere: +-- +2.54.0 + diff --git a/pkgs/by-name/ze/zelph/package.nix b/pkgs/by-name/ze/zelph/package.nix new file mode 100644 index 0000000000000..d5b12c6bf9426 --- /dev/null +++ b/pkgs/by-name/ze/zelph/package.nix @@ -0,0 +1,84 @@ +{ + lib, + stdenv, + fetchFromGitHub, + nix-update-script, + + # build-time + cmake, + janet, + meson, + ninja, + pkg-config, + + # run-time + bzip2, + capnproto, + doctest, + mimalloc, + unordered_dense, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "zelph"; + version = "1.0.1"; + __structuredAttrs = true; + strictDeps = true; + + src = fetchFromGitHub { + owner = "acrion"; + repo = "zelph"; + tag = "v${finalAttrs.version}"; + hash = "sha256-1bRgcYp9D9roNcerKpAc0yHCW9CmwFtI+rRxQxN+l7k="; + }; + + patches = [ + ./0001-Use-system-dependencies.patch + ]; + + nativeBuildInputs = [ + cmake + meson + ninja + pkg-config + ]; + + buildInputs = [ + bzip2 + capnproto + doctest + mimalloc + unordered_dense + ]; + + preConfigure = '' + cp -R ${janet.src} ./janet-src + chmod -R u+w ./janet-src + cmakeFlagsArray+=("-DJANET_SOURCE_DIR=$(pwd)/janet-src") + ''; + + passthru.updateScript = nix-update-script { }; + + meta = { + description = "Semantic network system and reasoning engine"; + longDescription = '' + zelph is a semantic network system and reasoning engine written in C++ + with an embedded Janet scripting layer. + + It treats logic, rules, and mathematics not as external code, but as + [homoiconic structures](https://en.wikipedia.org/wiki/Homoiconicity) within the graph itself. + + By blending the flexibility of semantic webs (like Wikidata) with logic + programming concepts (deep unification, constructive rules, negation as + failure), zelph effectively transforms a static knowledge base into an + executable graph. + ''; + homepage = "https://github.com/acrion/zelph"; + changelog = "https://github.com/acrion/zelph/releases/tag/${finalAttrs.src.tag}"; + mainProgram = "zelph"; + license = lib.licenses.agpl3Only; + platforms = lib.platforms.all; + maintainers = with lib.maintainers; [ eljamm ]; + teams = with lib.teams; [ ngi ]; + }; +}) From 3a7cc34e3999644cb8c195b83d0344969d32bbd4 Mon Sep 17 00:00:00 2001 From: eljamm Date: Fri, 11 Sep 2026 07:27:11 +0200 Subject: [PATCH 2/2] zelph: enable tests; add playground (brower demo) --- pkgs/by-name/ze/zelph/package.nix | 17 +++- pkgs/by-name/ze/zelph/playground.nix | 129 +++++++++++++++++++++++++++ 2 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 pkgs/by-name/ze/zelph/playground.nix diff --git a/pkgs/by-name/ze/zelph/package.nix b/pkgs/by-name/ze/zelph/package.nix index d5b12c6bf9426..64583d80f35a8 100644 --- a/pkgs/by-name/ze/zelph/package.nix +++ b/pkgs/by-name/ze/zelph/package.nix @@ -1,6 +1,7 @@ { lib, stdenv, + callPackage, fetchFromGitHub, nix-update-script, @@ -14,9 +15,11 @@ # run-time bzip2, capnproto, - doctest, mimalloc, unordered_dense, + + # tests + doctest, }: stdenv.mkDerivation (finalAttrs: { @@ -46,7 +49,6 @@ stdenv.mkDerivation (finalAttrs: { buildInputs = [ bzip2 capnproto - doctest mimalloc unordered_dense ]; @@ -57,7 +59,16 @@ stdenv.mkDerivation (finalAttrs: { cmakeFlagsArray+=("-DJANET_SOURCE_DIR=$(pwd)/janet-src") ''; - passthru.updateScript = nix-update-script { }; + checkInputs = [ + doctest + ]; + + doCheck = true; + + passthru = { + updateScript = nix-update-script { }; + playground = callPackage ./playground.nix { }; + }; meta = { description = "Semantic network system and reasoning engine"; diff --git a/pkgs/by-name/ze/zelph/playground.nix b/pkgs/by-name/ze/zelph/playground.nix new file mode 100644 index 0000000000000..c538896817a9e --- /dev/null +++ b/pkgs/by-name/ze/zelph/playground.nix @@ -0,0 +1,129 @@ +{ + lib, + buildEmscriptenPackage, + writeTextDir, + zelph, + serve, + xsel, + + # build-time + cmake, + janet, + makeWrapper, + meson, + ninja, + pkg-config, + + # run-time + unordered_dense, +}: + +let + # `unordered_dense` is header-only, but its installed CMake config rejects + # cross-compilation (CMAKE_SIZEOF_VOID_P 4 vs 8). + # + # Provide a config file that bypasses the arch check. + unordered_dense_config = writeTextDir "unordered_denseConfig.cmake" '' + set(unordered_dense_FOUND TRUE) + set(unordered_dense_VERSION "${unordered_dense.version}") + if(NOT TARGET unordered_dense::unordered_dense) + add_library(unordered_dense::unordered_dense INTERFACE IMPORTED) + set_target_properties(unordered_dense::unordered_dense PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${unordered_dense}/include" + ) + endif() + ''; +in + +buildEmscriptenPackage rec { + pname = "zelph-playground"; + + inherit (zelph) + version + src + patches + ; + + __structuredAttrs = true; + strictDeps = true; + + nativeBuildInputs = [ + cmake + makeWrapper + meson + ninja + pkg-config + ]; + + buildInputs = [ + unordered_dense + ]; + + cmakeFlags = [ + (lib.cmakeBool "ZELPH_WASM" true) + (lib.cmakeFeature "unordered_dense_DIR" "${unordered_dense_config}") + # warning: flexible array members are a C99 feature [-Wc99-extensions] + (lib.cmakeFeature "CMAKE_CXX_FLAGS" "-Wno-c99-extensions") + ]; + + cmakeBuildType = "Release"; + + preConfigure = '' + cp -R ${janet.src} ./janet-src + chmod -R u+w ./janet-src + cmakeFlagsArray+=("-DJANET_SOURCE_DIR=$(pwd)/janet-src") + ''; + + configurePhase = '' + runHook preConfigure + + mkdir -p .emscriptencache + export EM_CACHE=$(pwd)/.emscriptencache + + emcmake cmake -S . -B . "''${cmakeFlags[@]}" "''${cmakeFlagsArray[@]}" + + runHook postConfigure + ''; + + buildPhase = '' + runHook preBuild + + cmake --build . + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + cmake --install . --prefix $out + mkdir -p $out/share/zelph/playground + cp bin/zelph.mjs bin/zelph.wasm $out/share/zelph/playground/ + cp ${src}/src/wasm/web/* $out/share/zelph/playground/ + + runHook postInstall + ''; + + checkPhase = '' + runHook preCheck + + runHook postCheck + ''; + + postFixup = '' + makeWrapper ${lib.getExe serve} $out/bin/zelph-playground \ + --prefix PATH : ${lib.makeBinPath [ xsel ]} \ + --chdir $out/share/zelph/playground + ''; + + meta = zelph.meta // { + description = "Semantic network system and reasoning engine (WebAssembly)"; + longDescription = '' + The playground is the complete zelph reasoning engine — the same C++ core + as the native binaries — compiled to WebAssembly. + + It runs entirely in your browser; nothing is sent to a server. + ''; + mainProgram = "zelph-playground"; + }; +}