2025-04-04 13:26:45 -04:00

60 lines
2.1 KiB
Nix

{pkgs, lib, config, ...}:
with lib;
let
mkLauncher = import ../../packages/darwin-launcher.nix { inherit pkgs; };
ollamaLauncher = mkLauncher ''
exec ${pkgs.clio}/bin/clio \
--out-path=${config.services.ollama.stdoutPath} \
--err-path=${config.services.ollama.stdoutPath} \
--pid-file=${config.services.ollama.pidPath} \
--paranoid \
-- \
${pkgs.ollama}/bin/ollama \
serve
'';
in
{
options.services.ollama = {
enable = mkEnableOption "Enable the ollama agent";
stdoutPath = mkOption {
default = "/var/log/ollama.out.log";
};
stderrPath = mkOption {
default = "/var/log/ollama.err.log";
};
pidPath = mkOption {
default = "/var/log/ollama.pid";
};
user = mkOption {
default="zaphar";
};
};
config = {
launchd.user.agents.ollama = mkIf config.services.ollama.enable {
serviceConfig = {
ProgramArguments = [
"${ollamaLauncher}"
];
WatchPaths= [
"/etc/${config.environment.etc."ollama.yaml".target}"
];
EnvironmentVariables = {
"OLLAMA_HOST" = "127.0.0.1:11434";
"OLLAMA_MODELS" = "/Users/${config.services.ollama.user}/config/ollama";
};
RunAtLoad = true;
};
};
environment.etc."newsyslog.d/org.nixos.ollama.conf" = mkIf config.services.ollama.enable {
text = ''
# logfilename [owner:group] mode count size when flags [/pid_file] [sig_num]
${config.services.ollama.stdoutPath} zaphar:staff 644 10 1000 * BJ ${config.services.ollama.pidPath} 1
${config.services.ollama.stderrPath} zaphar:staff 644 10 1000 * BJ ${config.services.ollama.pidPath} 1
'';
};
};
}