From 5aa3a64596a1dc67a5aeb55dbd3d743f4d84126c Mon Sep 17 00:00:00 2001 From: Christian Hoener zu Siederdissen Date: Mon, 1 Jun 2026 20:01:26 +0200 Subject: [PATCH] nix : add nix-nodejs facilities to build Web UI (#23846) * nix: add nix-nodejs facilities to build Web UI Build the Web UI locally using standard Nix systems for building NodeJS packages. - Create derivation for the web UI - npm dependencies are imported via buildNodeModules. Does not require setting any shasum. - Copy build artifacts to the correct folders. - Prevents having to download from huggingface.co Fixes #23067 * nix: simplify webui derivation using LLAMA_UI_OUT_DIR - Move npm build to installPhase with LLAMA_UI_OUT_DIR=$out to write output directly to the Nix store - Copy built assets to tools/ui/dist (source tree) instead of build/tools/ui/dist so CMake's copy_src_dist() finds them --- .devops/nix/package.nix | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/.devops/nix/package.nix b/.devops/nix/package.nix index 30355d2fc9..86d9d589d3 100644 --- a/.devops/nix/package.nix +++ b/.devops/nix/package.nix @@ -3,6 +3,7 @@ glibc, config, stdenv, + stdenvNoCC, runCommand, cmake, ninja, @@ -19,6 +20,8 @@ openssl, shaderc, spirv-headers, + nodejs, + importNpmLock, useBlas ? builtins.all (x: !x) [ useCuda @@ -130,7 +133,31 @@ effectiveStdenv.mkDerivation (finalAttrs: { src = lib.cleanSource ../../.; }; - postPatch = '' + # Builds the webui locally, taking care not to require updating any sha256 hash. + webui = stdenvNoCC.mkDerivation { + pname = "webui"; + version = llamaVersion; + src = lib.cleanSource ../../tools/ui; + + nativeBuildInputs = [ + nodejs + importNpmLock.linkNodeModulesHook + ]; + + # no sha256 required when using buildNodeModules + npmDeps = importNpmLock.buildNodeModules { + npmRoot = ../../tools/ui; + inherit nodejs; + }; + + installPhase = '' + LLAMA_UI_OUT_DIR=$out npm run build --offline + ''; + }; + + postPatch = lib.optionalString useWebUi '' + cp -r ${finalAttrs.webui} tools/ui/dist + chmod -R u+w tools/ui/dist ''; # With PR#6015 https://github.com/ggml-org/llama.cpp/pull/6015,