From 2ef1bb2b3e6b4b3e2b4adc7976ca42b86967ff46 Mon Sep 17 00:00:00 2001 From: jaredmontoya <49511278+jaredmontoya@users.noreply.github.com> Date: Sun, 12 Jul 2026 11:56:05 +0200 Subject: [PATCH] nixos/llama-swap: option to share model cache with nixos/llama-cpp module --- .../services/networking/llama-swap.nix | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/nixos/modules/services/networking/llama-swap.nix b/nixos/modules/services/networking/llama-swap.nix index 3739e1b3f5de..b1ca322756db 100644 --- a/nixos/modules/services/networking/llama-swap.nix +++ b/nixos/modules/services/networking/llama-swap.nix @@ -42,6 +42,15 @@ in ''; }; + useLlamaCppCacheDir = lib.mkOption { + type = lib.types.bool; + default = false; + description = '' + Whether to use {file}`/var/cache/llama-cpp` as {env}`LLAMA_CACHE` instead + of {file}`/var/cache/llama-swap` to share models and other cache with {option}`services.llama-cpp`. + ''; + }; + tls = { enable = lib.mkEnableOption "TLS encryption"; @@ -113,6 +122,10 @@ in after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; + environment = { + LLAMA_CACHE = lib.mkDefault "/var/cache/${config.systemd.services.llama-swap.serviceConfig.CacheDirectory}"; + }; + serviceConfig = { Type = "exec"; ExecStart = "${lib.getExe cfg.package} ${ @@ -130,6 +143,12 @@ in Restart = "on-failure"; RestartSec = 3; + CacheDirectory = + if cfg.useLlamaCppCacheDir then + config.systemd.services.llama-cpp.serviceConfig.CacheDirectory + else + "llama-swap"; + # for GPU acceleration PrivateDevices = false;