llama-cpp.service: add support for --models-dir flag (#477593)

This commit is contained in:
Pascal Bach
2026-02-04 22:12:59 +00:00
committed by GitHub
+28 -3
View File
@@ -19,9 +19,17 @@ in
package = lib.mkPackageOption pkgs "llama-cpp" { };
model = lib.mkOption {
type = lib.types.path;
type = lib.types.nullOr lib.types.path;
example = "/models/mistral-instruct-7b/ggml-model-q4_0.gguf";
description = "Model path.";
default = null;
};
modelsDir = lib.mkOption {
type = lib.types.nullOr lib.types.path;
example = "/models/";
description = "Models directory.";
default = null;
};
extraFlags = lib.mkOption {
@@ -61,7 +69,6 @@ in
};
config = lib.mkIf cfg.enable {
systemd.services.llama-cpp = {
description = "LLaMA C++ server";
after = [ "network.target" ];
@@ -70,7 +77,25 @@ in
serviceConfig = {
Type = "idle";
KillSignal = "SIGINT";
ExecStart = "${cfg.package}/bin/llama-server --log-disable --host ${cfg.host} --port ${toString cfg.port} -m ${cfg.model} ${utils.escapeSystemdExecArgs cfg.extraFlags}";
ExecStart =
let
args = [
"--host"
cfg.host
"--port"
(toString cfg.port)
]
++ lib.optionals (cfg.model != null) [
"-m"
cfg.model
]
++ lib.optionals (cfg.modelsDir != null) [
"--models-dir"
cfg.modelsDir
]
++ cfg.extraFlags;
in
"${cfg.package}/bin/llama-server ${utils.escapeSystemdExecArgs args}";
Restart = "on-failure";
RestartSec = 300;