{ pkgs, kyojin, exllamav3, jitCheck, cpuCheck, }: let enginePatches = [ ./prefix-disk-admission.patch ./prefix-writer-release.patch ./prefix-inflight-pages.patch ./prefix-direct-write.patch ./prefix-split-segments.patch ./expert-direct-read-eof.patch ]; engine = exllamav3.overrideAttrs (old: { patches = (old.patches or [ ]) ++ enginePatches; }); # Both the upstream serve wrappers and the CPU check prepend the wheel to PYTHONPATH. withEngine = script: let updated = builtins.replaceStrings [ "${exllamav3}/" ] [ "${engine}/" ] script; in assert updated != script; updated; in kyojin.overrideAttrs (old: { installPhase = withEngine old.installPhase; # Upstream installs tools directly from $src, bypassing the unpacked tree. src = pkgs.applyPatches { src = old.src; patches = [ ./short-reply-prefill-grace.patch ./hip-blocking-sync.patch ]; }; nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.makeWrapper ]; meta = (old.meta or { }) // { homepage = "https://github.com/Yamz-Labs/kyojin"; license = pkgs.lib.licenses.mit; }; passthru = (old.passthru or { }) // { category = "AI Inference"; tests = (old.passthru.tests or { }) // { jit = jitCheck; cpu = cpuCheck.overrideAttrs (check: { patches = (check.patches or [ ]) ++ enginePatches; checkPhase = withEngine check.checkPhase; }); }; }; postFixup = '' # Fail the build, not the first request, if upstream renames the wrappers. ls "$out"/bin/kyojin-serve-* > /dev/null 2>&1 || { echo "kyojin-cc: no kyojin-serve-* in $out/bin; upstream moved them" >&2 exit 1 } for b in $out/bin/kyojin-serve-*; do wrapProgram "$b" --set CC ${pkgs.stdenv.cc}/bin/gcc done ''; })