{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 = "/Users/${config.services.ollama.user}/config/ollama/out.log"; }; stderrPath = mkOption { default = "/Users/${config.services.ollama.user}/config/ollama/err.log"; }; pidPath = mkOption { default = "/Users/${config.services.ollama.user}/config/ollama/ollama.pid"; }; user = mkOption { default="zaphar"; }; }; config = { launchd.user.agents.ollama = mkIf config.services.ollama.enable { serviceConfig = { ProgramArguments = [ "${ollamaLauncher}" ]; 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 ''; }; }; }