1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2025-02-04 07:15:04 +01:00

ollama: add darwin support

This commit is contained in:
Ivan Kovnatsky 2025-01-25 01:54:49 +02:00 committed by GitHub
parent 8c0671c513
commit daf04c5950
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 75 additions and 3 deletions

View file

@ -76,7 +76,7 @@ in {
};
config = mkIf cfg.enable {
systemd.user.services.ollama = {
systemd.user.services.ollama = mkIf pkgs.stdenv.isLinux {
Unit = {
Description = "Server for local large language models";
After = [ "network.target" ];
@ -92,6 +92,21 @@ in {
Install = { WantedBy = [ "default.target" ]; };
};
launchd.agents.ollama = mkIf pkgs.stdenv.isDarwin {
enable = true;
config = {
ProgramArguments = [ "${getExe ollamaPackage}" "serve" ];
EnvironmentVariables = cfg.environmentVariables // {
OLLAMA_HOST = "${cfg.host}:${toString cfg.port}";
};
KeepAlive = {
Crashed = true;
SuccessfulExit = false;
};
ProcessType = "Background";
};
};
home.packages = [ ollamaPackage ];
};
}

View file

@ -185,6 +185,7 @@ in import nmtSrc {
./modules/services/git-sync-darwin
./modules/services/imapnotify-darwin
./modules/services/nix-gc-darwin
./modules/services/ollama/darwin
./modules/targets-darwin
] ++ lib.optionals isLinux [
./modules/config/i18n
@ -270,7 +271,7 @@ in import nmtSrc {
./modules/services/mpd-mpris
./modules/services/mpdris2
./modules/services/nix-gc
./modules/services/ollama
./modules/services/ollama/linux
./modules/services/osmscout-server
./modules/services/pantalaimon
./modules/services/parcellite

View file

@ -0,0 +1,24 @@
{ lib, pkgs, ... }:
lib.mkMerge [
{
services.ollama = {
enable = true;
host = "localhost";
port = 11111;
environmentVariables = {
OLLAMA_LLM_LIBRARY = "cpu";
HIP_VISIBLE_DEVICES = "0,1";
};
};
test.stubs.ollama = { };
}
(lib.mkIf pkgs.stdenv.isDarwin {
nmt.script = ''
serviceFile=LaunchAgents/org.nix-community.home.ollama.plist
assertFileExists "$serviceFile"
assertFileContent "$serviceFile" ${./expected-agent.plist}
'';
})
]

View file

@ -0,0 +1 @@
{ ollama-darwin = ./basic.nix; }

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EnvironmentVariables</key>
<dict>
<key>HIP_VISIBLE_DEVICES</key>
<string>0,1</string>
<key>OLLAMA_HOST</key>
<string>localhost:11111</string>
<key>OLLAMA_LLM_LIBRARY</key>
<string>cpu</string>
</dict>
<key>KeepAlive</key>
<dict>
<key>Crashed</key>
<true/>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>Label</key>
<string>org.nix-community.home.ollama</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>
<array>
<string>@ollama@/bin/ollama</string>
<string>serve</string>
</array>
</dict>
</plist>

View file

@ -1,4 +1,4 @@
{
ollama-basic = ./basic.nix;
ollama-linux = ./basic.nix;
ollama-set-environment-variables = ./set-environment-variables.nix;
}