-
-
Notifications
You must be signed in to change notification settings - Fork 467
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
Conversation
I'm pretty new to Nix, and the whole language itself, so I could make some mistakes. I made this by example, copied |
This looks good to me. I assume you've tested it and it works on your computer? |
Yes, recently, I found that I had to add the service file to the modules list (see last commit). But then it worked in my personal configuration with: services.ollama.enable = true; Then, pull the model with: ollama pull zephyr # for example and the image is here and ready. |
Ah, one other thing. If you interact with the service using the |
Thank you for this PR! I believe you’d need to know the username to use NixOS already has a |
modules/services/ollama.nix
Outdated
|
||
models = mkOption { | ||
type = types.str; | ||
default = "%S/ollama/models"; |
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.
Need some help here. I didn't get why in nixpkgs
:
authors used string formatting specifier %S
by default, without inserting anything there and just directly passing into environmental variable:
In ollama
code, I can't find any string formatting related to models destination path. Am I missing something?
Also, actually,
ollama
uses$HOME/.ollama/models
by default:
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.
This is systemd‐specific syntax, documented in systemd.unit(5)
. I believe it would ordinarily expand to /var/lib
, but because of the DynamicUser
sandboxing it acts slightly differently (per systemd.exec(5)
):
If
DynamicUser=
is used, the logic forCacheDirectory=
,LogsDirectory=
andStateDirectory=
is slightly altered: the directories are created below/var/cache/private
,/var/log/private
and/var/lib/private
, respectively, which are host directories made inaccessible to unprivileged users, which ensures that access to these directories cannot be gained through dynamic user ID recycling. Symbolic links are created to hide this difference in behaviour. Both from perspective of the host and from inside the unit, the relevant directories hence always appear directly below/var/cache
,/var/log
and/var/lib
.
Since we don’t have the fancy DynamicUser
sandboxing on macOS, you can just read this as /var/lib
.
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 modules/services/gitlab-runner.nix
, modules/services/hercules-ci-agent/default.nix
, modules/services/ofborg/default.nix
, and modules/services/buildkite-agents.nix
for examples), set the daemon to run as that user, and use paths under /var/lib
here (although I don’t think that directory is commonly used on macOS). (I believe the current state of the PR would run Ollama as root
, which is definitely not what we want.)
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 launchd.agent
instead and default this stuff to $HOME/.ollama
or $HOME/LIbrary/Application Support/ollama
or something. That would isolate Ollama less than the NixOS module does, and mean that every interactive user gets their own copy of the Ollama data, but I don’t know if that really matters.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, seems that I'll return ollama.user.agents
back and use the same default as in ollama
: $HOME/.ollama/models
.
modules/services/ollama.nix
Outdated
|
||
home = lib.mkOption { | ||
type = types.str; | ||
default = "%S/ollama"; |
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
First of all, thank you all for your responses!
Yeah, as mentioned in issue #972, I was looking for something similiar to what I found in NixOS docs. So it makes total sense.
I did so by adding some of the options. With others, like: Maybe, I should add blank options with warnings, that won't be used, to make it compatible with existing NixOS module for now. |
Thanks! I think you can just omit |
6dbf183
to
dd4e6fb
Compare
@emilazy Currently, I'm a bit confused, directly setting I can't find an example in
|
Required due to missing services enable option on Darwin Ref: LnL7/nix-darwin#972
Required due to missing services enable option on Darwin Ref: LnL7/nix-darwin#972
Is this PR still current? Any alternative for an ollama service? |
@jyp you can add this to your system flake by copying the contents of ollama.nix (in this PR) to a local ollama.nix file, and importing it into your system flake. |
Particularly: host, port, home, models and environmentVariables, to make ollama module compatible with one from nixpkgs. Except: sandbox, writablePaths, acceleration, openFirewall.
This reverts commit 8ad6c8f.
Is it possible for ollama to run on the GPU with Intel Macs? I tried simply setting |
@tqwewe It seems to be experimental: Also, I'm on M2, so I can't figure it out either |
Closes: #971