0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-13 21:50:33 +03:00

nixos/ollama: add option to set environment variables

This commit is contained in:
abysssol 2024-03-14 02:57:42 -04:00
parent 58bdbbaecb
commit b5e7a05bb7

View file

@ -13,50 +13,62 @@ in
{ {
options = { options = {
services.ollama = { services.ollama = {
enable = lib.mkEnableOption ( enable = lib.mkEnableOption "ollama server for local large language models";
lib.mdDoc "Server for local large language models" package = lib.mkPackageOption pkgs "ollama" { };
);
listenAddress = lib.mkOption { listenAddress = lib.mkOption {
type = types.str; type = types.str;
default = "127.0.0.1:11434"; default = "127.0.0.1:11434";
description = lib.mdDoc '' example = "0.0.0.0:11111";
Specifies the bind address on which the ollama server HTTP interface listens. description = ''
The address which the ollama server HTTP interface binds and listens to.
''; '';
}; };
acceleration = lib.mkOption { acceleration = lib.mkOption {
type = types.nullOr (types.enum [ "rocm" "cuda" ]); type = types.nullOr (types.enum [ "rocm" "cuda" ]);
default = null; default = null;
example = "rocm"; example = "rocm";
description = lib.mdDoc '' description = ''
Specifies the interface to use for hardware acceleration. What interface to use for hardware acceleration.
- `rocm`: supported by modern AMD GPUs - `rocm`: supported by modern AMD GPUs
- `cuda`: supported by modern NVIDIA GPUs - `cuda`: supported by modern NVIDIA GPUs
''; '';
}; };
package = lib.mkPackageOption pkgs "ollama" { }; environmentVariables = lib.mkOption {
type = types.attrsOf types.str;
default = { };
example = {
HOME = "/tmp";
OLLAMA_LLM_LIBRARY = "cpu";
};
description = ''
Set arbitrary environment variables for the ollama service.
Be aware that these are only seen by the ollama server (systemd service),
not normal invocations like `ollama run`.
Since `ollama run` is mostly a shell around the ollama server, this is usually sufficient.
'';
};
}; };
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
systemd = { systemd.services.ollama = {
services.ollama = {
wantedBy = [ "multi-user.target" ];
description = "Server for local large language models"; description = "Server for local large language models";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ]; after = [ "network.target" ];
environment = { environment = cfg.environmentVariables // {
HOME = "%S/ollama"; HOME = "%S/ollama";
OLLAMA_MODELS = "%S/ollama/models"; OLLAMA_MODELS = "%S/ollama/models";
OLLAMA_HOST = cfg.listenAddress; OLLAMA_HOST = cfg.listenAddress;
}; };
serviceConfig = { serviceConfig = {
ExecStart = "${lib.getExe ollamaPackage} serve"; ExecStart = "${lib.getExe ollamaPackage} serve";
WorkingDirectory = "/var/lib/ollama"; WorkingDirectory = "%S/ollama";
StateDirectory = [ "ollama" ]; StateDirectory = [ "ollama" ];
DynamicUser = true; DynamicUser = true;
}; };
}; };
};
environment.systemPackages = [ ollamaPackage ]; environment.systemPackages = [ ollamaPackage ];
}; };