Merge pull request #314722 from abysssol/ollama-split-listenaddress

nixos/ollama: split `listenAddress` into `host` and `port`
This commit is contained in:
abysssol 2024-05-28 15:37:51 +00:00 committed by GitHub
commit c01818d57c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 12 deletions

@ -11,6 +11,11 @@ let
};
in
{
imports = [
(lib.mkRemovedOptionModule [ "services" "ollama" "listenAddress" ]
"Use `services.ollama.host` and `services.ollama.port` instead.")
];
options = {
services.ollama = {
enable = lib.mkEnableOption "ollama server for local large language models";
@ -64,12 +69,20 @@ in
See also `services.ollama.sandbox`.
'';
};
listenAddress = lib.mkOption {
host = lib.mkOption {
type = types.str;
default = "127.0.0.1:11434";
example = "0.0.0.0:11111";
default = "127.0.0.1";
example = "0.0.0.0";
description = ''
The address which the ollama server HTTP interface binds and listens to.
The host address which the ollama server HTTP interface listens to.
'';
};
port = lib.mkOption {
type = types.nullOr types.ints.u16;
default = 11434;
example = 11111;
description = ''
Which port the ollama server listens to. Set to `null` to not specify a port.
'';
};
acceleration = lib.mkOption {
@ -80,9 +93,9 @@ in
What interface to use for hardware acceleration.
- `null`: default behavior
if `nixpkgs.config.rocmSupport` is enabled, uses `"rocm"`
if `nixpkgs.config.cudaSupport` is enabled, uses `"cuda"`
otherwise defaults to `false`
- if `nixpkgs.config.rocmSupport` is enabled, uses `"rocm"`
- if `nixpkgs.config.cudaSupport` is enabled, uses `"cuda"`
- otherwise defaults to `false`
- `false`: disable GPU, only use CPU
- `"rocm"`: supported by most modern AMD GPUs
- `"cuda"`: supported by most modern NVIDIA GPUs
@ -114,7 +127,11 @@ in
environment = cfg.environmentVariables // {
HOME = cfg.home;
OLLAMA_MODELS = cfg.models;
OLLAMA_HOST = cfg.listenAddress;
OLLAMA_HOST =
if cfg.port == null then
cfg.host
else
"${cfg.host}:${toString cfg.port}";
};
serviceConfig = {
ExecStart = "${lib.getExe ollamaPackage} serve";

@ -1,10 +1,10 @@
import ./make-test-python.nix ({ pkgs, lib, ... }:
let
mainPort = "11434";
altPort = "11435";
mainPort = 11434;
altPort = 11435;
curlRequest = port: request:
"curl http://127.0.0.1:${port}/api/generate -d '${builtins.toJSON request}'";
"curl http://127.0.0.1:${toString port}/api/generate -d '${builtins.toJSON request}'";
prompt = {
model = "tinydolphin";
@ -38,7 +38,7 @@ in
altAddress = { ... }: {
services.ollama.enable = true;
services.ollama.listenAddress = "127.0.0.1:${altPort}";
services.ollama.port = altPort;
};
};