Skip to content

Commit

Permalink
Add some of the options from NixOS ollama module
Browse files Browse the repository at this point in the history
Particularly: host, port, home, models and environmentVariables, to make
ollama module compatible with one from nixpkgs.

Except: sandbox, writablePaths, acceleration, openFirewall.
  • Loading branch information
Velnbur committed Jun 16, 2024
1 parent 6290047 commit 3bc9998
Showing 1 changed file with 60 additions and 5 deletions.
65 changes: 60 additions & 5 deletions modules/services/ollama.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,75 @@ in {
description = "This option specifies the ollama package to use.";
};

exec = mkOption {
host = mkOption {
type = types.str;
default = "ollama";
description = "Ollama command/binary to execute.";
default = "127.0.0.1";
example = "0.0.0.0";
description = ''
The host address which the ollama server HTTP interface listens to.
'';
};

port = mkOption {
type = types.port;
default = 11434;
example = 11111;
description = ''
Which port the ollama server listens to.
'';
};

home = lib.mkOption {
type = types.str;
default = "%S/ollama";
example = "/home/foo";
description = ''
The home directory that the ollama service is started in.
See also `services.ollama.writablePaths` and `services.ollama.sandbox`.
'';
};

models = mkOption {
type = types.str;
default = "%S/ollama/models";
example = "/path/to/ollama/models";
description = ''
The directory that the ollama service will read models from and download new models to.
'';
};

environmentVariables = mkOption {
type = types.attrsOf types.str;
default = { };
example = {
OLLAMA_LLM_LIBRARY = "cpu";
HIP_VISIBLE_DEVICES = "0,1";
};
description = ''
Set arbitrary environment variables for the ollama service.
Be aware that these are only seen by the ollama server (launchd daemon),
not normal invocations like `ollama run`.
Since `ollama run` is mostly a shell around the ollama server, this is usually sufficient.
'';
};
};
};

config = mkIf cfg.enable {

environment.systemPackages = [ cfg.package ];
launchd.daemon.ollama = {
path = [ config.environment.systemPath ];
serviceConfig.ProgramArguments =
[ "${cfg.package}/bin/${cfg.exec}" "serve" ];

environment = cfg.environmentVariables // {
HOME = cfg.home;
OLLAMA_MODELS = cfg.models;
OLLAMA_HOST = "${cfg.host}:${toString cfg.port}";
};

serviceConfig.ProgramArguments = [ "${cfg.package}/bin/ollama" "serve" ];
serviceConfig.RunAtLoad = true;
};
};
Expand Down

0 comments on commit 3bc9998

Please sign in to comment.