Skip to content

Commit 5aa3a64

Browse files
authored
nix : add nix-nodejs facilities to build Web UI (ggml-org#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 ggml-org#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
1 parent 27d9ed8 commit 5aa3a64

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

.devops/nix/package.nix

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
glibc,
44
config,
55
stdenv,
6+
stdenvNoCC,
67
runCommand,
78
cmake,
89
ninja,
@@ -19,6 +20,8 @@
1920
openssl,
2021
shaderc,
2122
spirv-headers,
23+
nodejs,
24+
importNpmLock,
2225
useBlas ?
2326
builtins.all (x: !x) [
2427
useCuda
@@ -130,7 +133,31 @@ effectiveStdenv.mkDerivation (finalAttrs: {
130133
src = lib.cleanSource ../../.;
131134
};
132135

133-
postPatch = ''
136+
# Builds the webui locally, taking care not to require updating any sha256 hash.
137+
webui = stdenvNoCC.mkDerivation {
138+
pname = "webui";
139+
version = llamaVersion;
140+
src = lib.cleanSource ../../tools/ui;
141+
142+
nativeBuildInputs = [
143+
nodejs
144+
importNpmLock.linkNodeModulesHook
145+
];
146+
147+
# no sha256 required when using buildNodeModules
148+
npmDeps = importNpmLock.buildNodeModules {
149+
npmRoot = ../../tools/ui;
150+
inherit nodejs;
151+
};
152+
153+
installPhase = ''
154+
LLAMA_UI_OUT_DIR=$out npm run build --offline
155+
'';
156+
};
157+
158+
postPatch = lib.optionalString useWebUi ''
159+
cp -r ${finalAttrs.webui} tools/ui/dist
160+
chmod -R u+w tools/ui/dist
134161
'';
135162

136163
# With PR#6015 https://github.com/ggml-org/llama.cpp/pull/6015,

0 commit comments

Comments
 (0)