53 lines
1.3 KiB
Nix
53 lines
1.3 KiB
Nix
{
|
|
pkgs,
|
|
service_configs,
|
|
config,
|
|
inputs,
|
|
...
|
|
}:
|
|
let
|
|
|
|
# stolen from: https://stackoverflow.com/a/42398526
|
|
optimizeWithFlags =
|
|
pkg: flags:
|
|
pkgs.lib.overrideDerivation pkg (
|
|
old:
|
|
let
|
|
newflags = pkgs.lib.foldl' (acc: x: "${acc} ${x}") "" flags;
|
|
oldflags = if (pkgs.lib.hasAttr "NIX_CFLAGS_COMPILE" old) then "${old.NIX_CFLAGS_COMPILE}" else "";
|
|
in
|
|
{
|
|
NIX_CFLAGS_COMPILE = "${oldflags} ${newflags}";
|
|
stdenv = pkgs.clang19Stdenv;
|
|
}
|
|
);
|
|
in
|
|
{
|
|
services.llama-cpp = {
|
|
enable = true;
|
|
model = builtins.toString (
|
|
pkgs.fetchurl {
|
|
url = "https://huggingface.co/bartowski/google_gemma-3-12b-it-GGUF/resolve/main/google_gemma-3-12b-it-IQ4_XS.gguf";
|
|
sha256 = "aa7b7ae0b17931c379ede82da59b01f246046925aeb752af1ab4285a3b0d69db";
|
|
}
|
|
);
|
|
port = service_configs.ports.llama_cpp;
|
|
host = "0.0.0.0";
|
|
package = (
|
|
optimizeWithFlags inputs.llamacpp.packages.${pkgs.system}.default [
|
|
"-O3"
|
|
"-march=znver2"
|
|
"-mtune=znver2"
|
|
]
|
|
);
|
|
extraFlags = [
|
|
|
|
];
|
|
};
|
|
|
|
services.caddy.virtualHosts."llm.${service_configs.https.domain}".extraConfig = ''
|
|
${builtins.readFile ../secrets/caddy_auth}
|
|
reverse_proxy :${builtins.toString config.services.llama-cpp.port}
|
|
'';
|
|
}
|