build(packages): bump llama-cpp to b9159, add WebUI derivation, fix spec-type

- Bump llama-cpp from b9048 to b9159
- Add WebUI build derivation to work around HF bucket fetch in Nix sandbox
- Switch MTP patch from .patch to .diff (squashed unified diff applies cleanly)
- Refactor default.nix with let bindings for cleaner structure
- Add AGENTS.md documenting version/postFetch pitfalls
- Add qwen3.6-27b-vllm-50k single-GPU config to llama-swap
- Fix --spec-type from "mtp" to "draft-mtp" in llama.cpp configs
- Update update-package-hashes skill with fetchpatch/.diff guidance
This commit is contained in:
2026-05-15 11:14:44 -04:00
parent eaf307db23
commit 4e2d03ae89
4 changed files with 182 additions and 25 deletions

View File

@@ -0,0 +1,35 @@
# llama-cpp — Agent Notes
Override of `pkgs.llama-cpp` with CUDA + Vulkan + BLAS, custom CMake flags, and an optional fork pin.
## Pitfalls
### `version` must be numeric
Upstream `pkgs/by-name/ll/llama-cpp/package.nix` passes `version` straight through as a C integer via:
```nix
(cmakeFeature "LLAMA_BUILD_NUMBER" finalAttrs.version)
```
`build-info.cpp` then emits `int LLAMA_BUILD_NUMBER = <version>;`. A non-numeric `version` (e.g. `"mtp-clean-08b1474"`) breaks the build with:
```
error: '<value>' was not declared in this scope
int LLAMA_BUILD_NUMBER = <value>;
```
**Convention:**
- Upstream tag pins: use the bare build number, e.g. `version = "9048";` with `tag = "b${version}";`.
- Fork / arbitrary commit pins: use a `YYYYMMDD` date derived from the commit's author/commit date (`gh api repos/<owner>/<repo>/commits/<sha>``.commit.committer.date`).
### `leaveDotGit` + `postFetch`
We keep `.git` only long enough to record the short SHA into `$out/COMMIT`, then strip it. Preserve this pattern when changing `src` so downstream tooling that reads `COMMIT` keeps working.
## Refreshing the pinned commit (fork)
1. `git ls-remote https://github.com/<owner>/llama.cpp refs/heads/<branch>` → get the full SHA.
2. `nix run nixpkgs#nix-prefetch-github -- <owner> llama.cpp --rev <sha> --leave-dot-git` → get the hash.
3. Look up the commit date: `curl -s https://api.github.com/repos/<owner>/llama.cpp/commits/<sha> | jq -r '.commit.committer.date'`.
4. Update `src.{owner,rev,hash}` and set `version = "YYYYMMDD"`.

View File

@@ -1,4 +1,75 @@
{ pkgs }:
let
version = "9159";
src = pkgs.fetchFromGitHub {
owner = "ggml-org";
repo = "llama.cpp";
tag = "b${version}";
hash = "sha256-y69ZmVFxo7bQvLTT6/GWwkb5j4Ll8eXSVXFpfXVkvyg=";
leaveDotGit = true;
postFetch = ''
git -C "$out" rev-parse --short HEAD > $out/COMMIT
find "$out" -name .git -print0 | xargs -0 rm -rf
'';
};
# MTP Patch (PR #22673)
# Use the .diff (squashed) endpoint, not .patch (mbox of commits).
mtpPatch = pkgs.fetchpatch {
name = "mtp.patch";
url = "https://github.com/ggml-org/llama.cpp/pull/22673.diff";
hash = "sha256-8W02V7oqq2/SzSrDUHEa5Zm+dGBFkasOiVinww3V85U=";
};
# Pre-Built WebUI Assets
# As of b9151 llama.cpp removed the prebuilt WebUI from the repo and tries to
# curl them from a HuggingFace bucket at build time. That fails in the Nix
# sandbox. We build the WebUI from source in a separate derivation and drop
# the 4 output files into tools/server/public/ so cmake's "Priority 1: local
# assets present" branch short-circuits the network fetch.
# Vendored npm deps. The npmDeps FOD uses default unpack and looks for
# package-lock.json at sourceRoot, so point it directly at the webui dir.
webuiNpmDeps = pkgs.fetchNpmDeps {
name = "llama-webui-${version}-npm-deps";
inherit src;
sourceRoot = "${src.name}/tools/server/webui";
hash = "sha256-WaEePrEZ7O/7deP2KJhe0AwiSKYA8HOqETmMHUkmBe0=";
};
webui = pkgs.buildNpmPackage {
pname = "llama-webui";
inherit version src;
# Custom unpack: the vite plugin writes to ../public, so both webui/ and
# public/ must be writable siblings under tools/server/. Plain sourceRoot
# leaves the parent dirs in the read-only Nix store.
unpackPhase = ''
runHook preUnpack
cp -r ${src}/tools/server tools-server
chmod -R u+w tools-server
cd tools-server/webui
runHook postUnpack
'';
npmDeps = webuiNpmDeps;
# The vite plugin writes to ../public; ensure it exists.
preBuild = ''
mkdir -p ../public
'';
installPhase = ''
runHook preInstall
mkdir -p $out
install -Dm644 ../public/index.html $out/index.html
install -Dm644 ../public/bundle.js $out/bundle.js
install -Dm644 ../public/bundle.css $out/bundle.css
install -Dm644 ../public/loading.html $out/loading.html
runHook postInstall
'';
};
in
(pkgs.llama-cpp.override {
cudaSupport = true;
blasSupport = true;
@@ -6,19 +77,8 @@
metalSupport = false;
vulkanSupport = true;
}).overrideAttrs
(oldAttrs: rec {
version = "9048";
src = pkgs.fetchFromGitHub {
owner = "ggml-org";
repo = "llama.cpp";
tag = "b${version}";
hash = "sha256-lYtX0hLReCnFw1+xOKefly+WunuoN89ZFEFl5mK5pQ4=";
leaveDotGit = true;
postFetch = ''
git -C "$out" rev-parse --short HEAD > $out/COMMIT
find "$out" -name .git -print0 | xargs -0 rm -rf
'';
};
(oldAttrs: {
inherit version src;
# Add SPIR-V Headers for Vulkan Backend
# Newer llama.cpp requires spirv/unified1/spirv.hpp which isn't
@@ -39,11 +99,17 @@
# Apply Patches
patchFlags = [ "-p1" ];
patches = (oldAttrs.patches or [ ]) ++ [
(pkgs.fetchpatch {
name = "mtp.patch";
url = "https://github.com/ggml-org/llama.cpp/pull/22673.patch";
hash = "sha256-HqpchhOpxuw5mY4a/OCWGDr2Y32rC4FeOHuhaVt+mvY=";
})
];
patches = (oldAttrs.patches or [ ]) ++ [ mtpPatch ];
# Drop pre-built WebUI assets into tools/server/public/ so cmake's
# Priority 1 path picks them up and skips the HF Bucket fetch.
postPatch = ''
${oldAttrs.postPatch or ""}
mkdir -p tools/server/public
cp ${webui}/* tools/server/public/
'';
# Expose the WebUI sub-derivation so it can be built/tested in isolation:
# nix build .#llama-cpp.webui --builders ''
passthru = (oldAttrs.passthru or { }) // { inherit webui; };
})