-
Notifications
You must be signed in to change notification settings - Fork 407
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
base: master
Are you sure you want to change the base?
Add ollama
service
#972
Changes from 6 commits
30029ae
054f16d
8ad6c8f
545b564
04fd278
5df2ab6
4c31a81
6891635
a25675f
45a7346
585e301
a29120c
1c4d6a7
dd4e6fb
fb399d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
with lib; | ||
|
||
let | ||
|
||
cfg = config.services.ollama; | ||
|
||
in { | ||
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. | ||
''; | ||
}; | ||
|
||
home = lib.mkOption { | ||
type = types.str; | ||
default = "%S/ollama"; | ||
example = "/home/foo"; | ||
description = '' | ||
The home directory that the ollama service is started in. | ||
''; | ||
}; | ||
|
||
models = mkOption { | ||
type = types.str; | ||
default = "%S/ollama/models"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need some help here. I didn't get why in authors used string formatting specifier In
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is systemd‐specific syntax, documented in
Since we don’t have the fancy So basically we have a choice here. The thing that would best match NixOS is to define a user for this to run as (see However, defining users on macOS is a bit annoying – they show up in System Settings and can potentially cause fuss on system upgrades unless you use a ~100 UID range that Apple keeps encroaching on and that Nix already puts 32 users in. So an alternative would be to define a Ideally we’d have a better story for defining daemon users, but for now the latter approach may be more practical. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, seems that I'll return |
||
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.daemons.ollama = { | ||
path = [ config.environment.systemPath ]; | ||
|
||
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; | ||
}; | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same here