diff --git a/nix/base-system/darwin-configuration.nix b/nix/base-system/darwin-configuration.nix index 8efba2f..9842fbe 100644 --- a/nix/base-system/darwin-configuration.nix +++ b/nix/base-system/darwin-configuration.nix @@ -44,6 +44,10 @@ in # }; #}; + services.ollama = { + enable = true; + user="zaphar"; + }; services.my-lorri.enable = true; services.durnitisp.enable = true; services.node-exporter.enable = true; diff --git a/nix/base-system/flake.nix b/nix/base-system/flake.nix index bc44ce0..5d774c2 100644 --- a/nix/base-system/flake.nix +++ b/nix/base-system/flake.nix @@ -369,6 +369,8 @@ EOF"; victoriametrics # TODO add sonic-pi here if it supports the arch unstablePkgs.dbeaver-bin + postgresql + unstablePkgs.ollama ]) #++ (with pkgs.ocamlPackages; [ # dune_3 @@ -397,6 +399,7 @@ EOF"; ./modules/victoria-logs.nix ./modules/vector.nix ./modules/lorri.nix + ./modules/ollama.nix ./darwin-configuration.nix ]; }; diff --git a/nix/base-system/modules/ollama.nix b/nix/base-system/modules/ollama.nix new file mode 100644 index 0000000..6361348 --- /dev/null +++ b/nix/base-system/modules/ollama.nix @@ -0,0 +1,59 @@ +{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 + ''; + }; + }; +}