Skip to content

fix(nixos): fix prebuilt binaries via LD_LIBRARY_PATH + skip source build on read-only install#574

Open
jerome-benoit wants to merge 1 commit intotobi:mainfrom
jerome-benoit:fix/nixos-llama-build-dir
Open

fix(nixos): fix prebuilt binaries via LD_LIBRARY_PATH + skip source build on read-only install#574
jerome-benoit wants to merge 1 commit intotobi:mainfrom
jerome-benoit:fix/nixos-llama-build-dir

Conversation

@jerome-benoit
Copy link
Copy Markdown

@jerome-benoit jerome-benoit commented Apr 14, 2026

Summary

On NixOS (and other immutable-root systems), qmd embed crashes with EACCES because node-llama-cpp tries to compile llama.cpp into its read-only node_modules/ directory inside /nix/store. Even when source builds are skipped, the prebuilt binaries fail because they expect FHS paths like /lib64/libc.so.6 which don't exist on NixOS.

Two fixes:

  1. LD_LIBRARY_PATH in wrapper — the flake wrapper sets LD_LIBRARY_PATH to include Nix's glibc and libstdc++, covering what the prebuilt binaries need without modifying them
  2. skip source builds when the install directory is read-only (canWriteLlamaDir())

Changes

  • flake.nix: Add glibc and libstdc++ to LD_LIBRARY_PATH in the wrapper. No binary modification needed — LD_LIBRARY_PATH takes precedence over RUNPATH for dlopen.
  • src/llm.ts: Add canWriteLlamaDir() that probes write access on node-llama-cpp's llama/ directory. When unwritable, ensureLlama() passes build: "never" to getLlama().
  • CHANGELOG.md: Unreleased entry under Fixes.

Closes #87

Testing

  • nix build succeeds
  • ./result/bin/qmd status shows CPU backend loaded, no EACCES, no NoBinaryFoundError
  • ./result/bin/qmd embed completes successfully

Copilot AI review requested due to automatic review settings April 14, 2026 16:42
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses NixOS/immutable-root failures when node-llama-cpp attempts to write compiled llama.cpp artifacts into a read-only node_modules path (e.g. under /nix/store) by redirecting build output to a user-writable cache directory.

Changes:

  • Add resolveLlamaBuildDir() (+ QMD_LLAMA_BUILD_DIR) to compute a user-writable llama build directory following XDG cache conventions.
  • Patch node-llama-cpp/dist/config.js during the Nix build to honor NODE_LLAMA_CPP_LOCAL_BUILDS_DIR, and set that env var in the Nix wrapper before JS starts.
  • Document the fix in CHANGELOG.md and ignore generated node-llama-cpp-*.tgz artifacts.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/llm.ts Adds a helper + default constant for resolving a writable llama build directory (XDG-based, env-overridable).
flake.nix Applies a build-time patch to node-llama-cpp config and sets NODE_LLAMA_CPP_LOCAL_BUILDS_DIR in the wrapper.
CHANGELOG.md Adds an Unreleased “Fixes” entry describing the NixOS redirect behavior and env vars.
.gitignore Ignores node-llama-cpp-*.tgz artifacts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/llm.ts Outdated
Comment thread CHANGELOG.md Outdated
Comment thread src/llm.ts Outdated
Comment thread src/llm.ts Outdated
@jerome-benoit jerome-benoit marked this pull request as draft April 14, 2026 17:40
@jerome-benoit jerome-benoit force-pushed the fix/nixos-llama-build-dir branch from bd62472 to a239e7e Compare April 14, 2026 23:13
@jerome-benoit jerome-benoit changed the title fix(nixos): redirect node-llama-cpp build output to user-writable directory fix(nixos): skip llama.cpp source build when install dir is read-only Apr 14, 2026
@jerome-benoit jerome-benoit marked this pull request as ready for review April 14, 2026 23:14
@jerome-benoit jerome-benoit marked this pull request as draft April 14, 2026 23:17
@jerome-benoit jerome-benoit force-pushed the fix/nixos-llama-build-dir branch from a239e7e to 8bbb71c Compare April 14, 2026 23:33
@jerome-benoit jerome-benoit changed the title fix(nixos): skip llama.cpp source build when install dir is read-only fix(nixos): patchelf prebuilt binaries + skip source build on read-only install Apr 14, 2026
@jerome-benoit jerome-benoit force-pushed the fix/nixos-llama-build-dir branch 2 times, most recently from 25fb143 to 0c9f8cd Compare April 14, 2026 23:58
@jerome-benoit jerome-benoit changed the title fix(nixos): patchelf prebuilt binaries + skip source build on read-only install fix(nixos): fix prebuilt binaries via LD_LIBRARY_PATH + skip source build on read-only install Apr 15, 2026
@jerome-benoit jerome-benoit marked this pull request as ready for review April 15, 2026 15:21
@jerome-benoit jerome-benoit changed the title fix(nixos): fix prebuilt binaries via LD_LIBRARY_PATH + skip source build on read-only install fix(nixos): fix prebuilt binaries via LD_LIBRARY_PATH + skip source build on read-only install Closes #87 Apr 15, 2026
@jerome-benoit jerome-benoit changed the title fix(nixos): fix prebuilt binaries via LD_LIBRARY_PATH + skip source build on read-only install Closes #87 fix(nixos): fix prebuilt binaries via LD_LIBRARY_PATH + skip source build on read-only install Apr 15, 2026
@jerome-benoit jerome-benoit force-pushed the fix/nixos-llama-build-dir branch from 2999f90 to 029a898 Compare April 16, 2026 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emebeding fails on NixOS (node-llama-cpp)

2 participants