From d05f1a02a1dc5c2dca139f9e05aa41a371dcd026 Mon Sep 17 00:00:00 2001 From: agentelement Date: Thu, 22 Jan 2026 15:03:26 -0700 Subject: [PATCH 1/4] llama-cpp: add support for --models-dir flag --- nixos/modules/services/misc/llama-cpp.nix | 25 +++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/nixos/modules/services/misc/llama-cpp.nix b/nixos/modules/services/misc/llama-cpp.nix index fbbd8125db36..82c92f99afd6 100644 --- a/nixos/modules/services/misc/llama-cpp.nix +++ b/nixos/modules/services/misc/llama-cpp.nix @@ -19,11 +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."; }; + modelsDir = lib.mkOption { + type = lib.types.nullOr lib.types.path; + example = "/models/"; + description = "Models directory."; + }; + extraFlags = lib.mkOption { type = lib.types.listOf lib.types.str; description = "Extra flags passed to llama-cpp-server."; @@ -61,6 +67,13 @@ in }; config = lib.mkIf cfg.enable { + # Enforce that either model or modelDir is set + assertions = [ + { + assertion = cfg.model != null || cfg.modelsDir != null; + message = "services.llama-cpp: Either 'model' or 'modelDir' must be set."; + } + ]; systemd.services.llama-cpp = { description = "LLaMA C++ server"; @@ -70,7 +83,15 @@ 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; From b84fe8afc261cf98e7019fedd6a9169e83bd87e4 Mon Sep 17 00:00:00 2001 From: agentelement Date: Tue, 6 Jan 2026 16:26:26 -0700 Subject: [PATCH 2/4] llama-cpp: make models and modelsDir default null --- nixos/modules/services/misc/llama-cpp.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nixos/modules/services/misc/llama-cpp.nix b/nixos/modules/services/misc/llama-cpp.nix index 82c92f99afd6..6da2017f65fd 100644 --- a/nixos/modules/services/misc/llama-cpp.nix +++ b/nixos/modules/services/misc/llama-cpp.nix @@ -22,12 +22,14 @@ in 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 { From f7f3858a24eaf260741d04d697a0b36c9bacd865 Mon Sep 17 00:00:00 2001 From: agentelement Date: Tue, 6 Jan 2026 16:39:56 -0700 Subject: [PATCH 3/4] llama-cpp: run nix fmt --- nixos/modules/services/misc/llama-cpp.nix | 28 +++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/nixos/modules/services/misc/llama-cpp.nix b/nixos/modules/services/misc/llama-cpp.nix index 6da2017f65fd..2bfd36459ba4 100644 --- a/nixos/modules/services/misc/llama-cpp.nix +++ b/nixos/modules/services/misc/llama-cpp.nix @@ -85,15 +85,25 @@ in serviceConfig = { Type = "idle"; KillSignal = "SIGINT"; - 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}"; + 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; From 653f976dd45a98abceb5ad4940579f59fc93ecaa Mon Sep 17 00:00:00 2001 From: agentelement Date: Sun, 1 Feb 2026 16:44:51 -0700 Subject: [PATCH 4/4] llama-cpp: remove required models or modelsDir assertion --- nixos/modules/services/misc/llama-cpp.nix | 8 -------- 1 file changed, 8 deletions(-) diff --git a/nixos/modules/services/misc/llama-cpp.nix b/nixos/modules/services/misc/llama-cpp.nix index 2bfd36459ba4..65ed2880b0b2 100644 --- a/nixos/modules/services/misc/llama-cpp.nix +++ b/nixos/modules/services/misc/llama-cpp.nix @@ -69,14 +69,6 @@ in }; config = lib.mkIf cfg.enable { - # Enforce that either model or modelDir is set - assertions = [ - { - assertion = cfg.model != null || cfg.modelsDir != null; - message = "services.llama-cpp: Either 'model' or 'modelDir' must be set."; - } - ]; - systemd.services.llama-cpp = { description = "LLaMA C++ server"; after = [ "network.target" ];