git: df771808d6a1 - main - misc/ollama: Add config variables ollama_context_length and llama_use_vulkan to ollama service

From: Yuri Victorovich <yuri_at_FreeBSD.org>
Date: Sun, 29 Mar 2026 22:57:57 UTC
The branch main has been updated by yuri:

URL: https://cgit.FreeBSD.org/ports/commit/?id=df771808d6a11dc67b1e7ede473528d07a83a000

commit df771808d6a11dc67b1e7ede473528d07a83a000
Author:     Yuri Victorovich <yuri@FreeBSD.org>
AuthorDate: 2026-03-29 22:57:10 +0000
Commit:     Yuri Victorovich <yuri@FreeBSD.org>
CommitDate: 2026-03-29 22:57:55 +0000

    misc/ollama: Add config variables ollama_context_length and llama_use_vulkan to ollama service
---
 misc/ollama/Makefile        |  2 +-
 misc/ollama/files/ollama.in | 35 ++++++++++++++++++++++++-----------
 misc/ollama/pkg-message     |  4 ++++
 3 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/misc/ollama/Makefile b/misc/ollama/Makefile
index 0bc5709974d3..9775f633c536 100644
--- a/misc/ollama/Makefile
+++ b/misc/ollama/Makefile
@@ -1,7 +1,7 @@
 PORTNAME=	ollama
 DISTVERSIONPREFIX=	v
 DISTVERSION=	0.18.3
-PORTREVISION=	3
+PORTREVISION=	4
 CATEGORIES=	misc # machine-learning
 
 MAINTAINER=	yuri@FreeBSD.org
diff --git a/misc/ollama/files/ollama.in b/misc/ollama/files/ollama.in
index c6ea19ebd8ad..a70a905e2ed6 100644
--- a/misc/ollama/files/ollama.in
+++ b/misc/ollama/files/ollama.in
@@ -7,16 +7,20 @@
 # Add the following lines to /etc/rc.conf to enable ollama
 # ollama_enable="YES"
 #
-# ollama_enable (bool):  Set to YES to enable ollama
-#                        Default: NO
-# ollama_user (str):     Ollama daemon user
-#                        Default: %%USER%%
-# ollama_args (str):     Additional arguments for ollama
-#                        Default: ""
-# ollama_log (str):      Log file for ollama
-#                        Default: "/var/log/ollama.log"
-# ollama_pidfile (str):  PID file for ollama
-#                        Default: "/var/run/ollama.pid"
+# ollama_enable (bool):    Set to YES to enable ollama
+#                          Default: NO
+# ollama_user (str):       Ollama daemon user
+#                          Default: root
+# ollama_args (str):       Additional arguments for ollama
+#                          Default: ""
+# ollama_log (str):        Log file for ollama
+#                          Default: "/var/log/ollama-$user.log"
+# ollama_pidfile (str):    PID file for ollama
+#                          Default: "/var/run/ollama-$user.pid"
+# ollama_context_length (int): Context length for ollama (OLLAMA_CONTEXT_LENGTH)
+#                          Default: 65536
+# ollama_use_vulkan (int): Use Vulkan (OLLAMA_VULKAN)
+#                          Default: 0
 
 . /etc/rc.subr
 
@@ -26,10 +30,12 @@ rcvar=ollama_enable
 load_rc_config $name
 
 : ${ollama_enable:="NO"}
-: ${ollama_user:="root"} # the user nobody doesn't have a home diectory and ollama needs one to store the models
+: ${ollama_user:="root"} # the user nobody doesn't have a home directory and ollama needs one to store the models
 : ${ollama_args:="serve"}
 : ${ollama_log:="/var/log/ollama-${ollama_user}.log"}
 : ${ollama_pidfile:="/var/run/${name}-${ollama_user}.pid"}
+: ${ollama_context_length:="65536"}
+: ${ollama_use_vulkan:="0"}
 
 run_command="%%PREFIX%%/bin/ollama"
 procname="${run_command}"
@@ -42,6 +48,13 @@ ollama_chdir=/tmp
 
 ollama_precmd()
 {
+    # set environment variables for the ollama server
+    export OLLAMA_CONTEXT_LENGTH=${ollama_context_length}
+    if [ "$ollama_use_vulkan" != "0" ]; then
+        export OLLAMA_VULKAN=1
+    else
+        export OLLAMA_VULKAN=0
+    fi
     # ensure log file exists
     touch ${ollama_log} ${pidfile}
     chown ${ollama_user} ${ollama_log} ${pidfile}
diff --git a/misc/ollama/pkg-message b/misc/ollama/pkg-message
index 87e28efb446c..0ad67fb6566c 100644
--- a/misc/ollama/pkg-message
+++ b/misc/ollama/pkg-message
@@ -31,6 +31,8 @@ Please symlink ~/.ollama to a large disk if needed.
 Working examples:
 (1) Coding with the model gpt-oss:20b:
   1. run 'OLLAMA_CONTEXT_LENGTH=65536 ollama serve'
+     or
+     setup and start the service 'ollama'
   2. install claude-code and run:
      ANTHROPIC_BASE_URL=http://localhost:11434 \
      ANTHROPIC_AUTH_TOKEN=ollama \
@@ -43,6 +45,8 @@ Working examples:
 
 (2) Image generation with the model x/z-image-turbo:
   1. run 'OLLAMA_CONTEXT_LENGTH=65536 ollama serve'
+     or
+     setup and start the service 'ollama'
   2. install claude-code and run:
      ollama run x/z-image-turbo {textual description of the desired image}