Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ollama service #972

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
./services/cachix-agent.nix
./services/dnsmasq.nix
./services/emacs.nix
./services/ollama.nix
./services/eternal-terminal.nix
./services/github-runner
./services/gitlab-runner.nix
Expand Down
91 changes: 91 additions & 0 deletions modules/services/ollama.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{ config, lib, pkgs, ... }:

with lib;

let

cfg = config.services.ollama;

in {
meta.maintainers = [ "velnbur" ];

options = {
services.ollama = {
enable = mkOption {
type = types.bool;
default = false;
description = "Whether to enable the Ollama Daemon.";
};

package = mkOption {
type = types.path;
default = pkgs.ollama;
description = "This option specifies the ollama package to use.";
};

host = mkOption {
type = types.str;
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.
'';
};

models = mkOption {
type = types.nullOr types.str;
default = null;
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.user.agents.ollama = {
path = [ config.environment.systemPath ];

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

EnvironmentVariables = cfg.environmentVariables // {
OLLAMA_HOST = "${cfg.host}:${toString cfg.port}";
} // (optionalAttrs (cfg.models != null) {
OLLAMA_MODELS = cfg.models;
});
};
};
};
}
Loading