From 97b35f64203727331dc095664934070eef9e827d Mon Sep 17 00:00:00 2001 From: Pascal Bach Date: Thu, 5 Feb 2026 20:22:55 +0100 Subject: [PATCH 1/2] nixos/llama-cpp: add state and cache directory This is required to allow automatic download from huggingface etc. They are placed in LLAMA_CACHE which is now the cache directory. --- nixos/modules/services/misc/llama-cpp.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nixos/modules/services/misc/llama-cpp.nix b/nixos/modules/services/misc/llama-cpp.nix index 65ed2880b0b2..df9538d5137c 100644 --- a/nixos/modules/services/misc/llama-cpp.nix +++ b/nixos/modules/services/misc/llama-cpp.nix @@ -77,6 +77,10 @@ in serviceConfig = { Type = "idle"; KillSignal = "SIGINT"; + StateDirectory = "llama-cpp"; + CacheDirectory = "llama-cpp"; + WorkingDirectory = "/var/lib/llama-cpp"; + Environment = [ "LLAMA_CACHE=/var/cache/llama-cpp" ]; ExecStart = let args = [ From 676d8fc1bc1ff02f35392ba26577236d06c68838 Mon Sep 17 00:00:00 2001 From: Pascal Bach Date: Thu, 5 Feb 2026 20:23:11 +0100 Subject: [PATCH 2/2] nixos/llama-cpp: support models-preset The new options allows specifying --models-preset via Nix. --- nixos/modules/services/misc/llama-cpp.nix | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/nixos/modules/services/misc/llama-cpp.nix b/nixos/modules/services/misc/llama-cpp.nix index df9538d5137c..fdf306ab5256 100644 --- a/nixos/modules/services/misc/llama-cpp.nix +++ b/nixos/modules/services/misc/llama-cpp.nix @@ -8,6 +8,12 @@ let cfg = config.services.llama-cpp; + + modelsPresetFile = + if cfg.modelsPreset != null then + pkgs.writeText "llama-models.ini" (lib.generators.toINI { } cfg.modelsPreset) + else + null; in { @@ -32,6 +38,32 @@ in default = null; }; + modelsPreset = lib.mkOption { + type = lib.types.nullOr (lib.types.attrsOf lib.types.attrs); + default = null; + description = '' + Models preset configuration as a Nix attribute set. + This is converted to an INI file and passed to llama-server via --model-preset. + See llama-server documentation for available options. + ''; + example = lib.literalExpression '' + { + "Qwen3-Coder-Next" = { + hf-repo = "unsloth/Qwen3-Coder-Next-GGUF"; + hf-file = "Qwen3-Coder-Next-UD-Q4_K_XL.gguf"; + alias = "unsloth/Qwen3-Coder-Next"; + fit = "on"; + seed = "3407"; + temp = "1.0"; + top-p = "0.95"; + min-p = "0.01"; + top-k = "40"; + jinja = "on"; + }; + } + ''; + }; + extraFlags = lib.mkOption { type = lib.types.listOf lib.types.str; description = "Extra flags passed to llama-cpp-server."; @@ -97,6 +129,10 @@ in "--models-dir" cfg.modelsDir ] + ++ lib.optionals (cfg.modelsPreset != null) [ + "--models-preset" + modelsPresetFile + ] ++ cfg.extraFlags; in "${cfg.package}/bin/llama-server ${utils.escapeSystemdExecArgs args}";