From 1deec9093abbaca3a2d5dcdf196295d0c4e67b7a Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Mon, 27 Nov 2023 23:55:04 +0000 Subject: [PATCH] Add ollama daemon --- home/default.nix | 1 + home/ollama.nix | 41 +++++++++++++++++++++++++++++++++++++++++ lib/helpers.nix | 2 ++ 3 files changed, 44 insertions(+) create mode 100644 home/ollama.nix diff --git a/home/default.nix b/home/default.nix index 35184e0..ff3c7ed 100644 --- a/home/default.nix +++ b/home/default.nix @@ -6,6 +6,7 @@ ./zsh.nix ./tmux.nix ./rbw.nix + ./ollama.nix ./wezterm ./npm ./gpg diff --git a/home/ollama.nix b/home/ollama.nix new file mode 100644 index 0000000..27c9904 --- /dev/null +++ b/home/ollama.nix @@ -0,0 +1,41 @@ +{ helpers, lib, pkgs, ... }: + +let + ollamaArgs = [ + "${pkgs.ollama}/bin/ollama" + "serve" + ]; +in { + config = lib.mkMerge [ + { home.packages = [ pkgs.ollama ]; } + + (helpers.mkIfLinux { + systemd.user.services.ollama = { + Unit = { + Description = "Ollama"; + Documentation = "https://github.com/jmorganca/ollama"; + }; + Install.WantedBy = [ "default.target" ]; + Service = { + ExecStart = lib.escapeShellArgs ollamaArgs; + Restart = "on-failure"; + RestartSec = 5; + }; + }; + }) + + (helpers.mkIfDarwin { + launchd.agents.ollama = { + enable = true; + config = { + ProcessType = "Background"; + ProgramArguments = ollamaArgs; + KeepAlive = { + Crashed = true; + SuccessfulExit = false; + }; + }; + }; + }) + ]; +} diff --git a/lib/helpers.nix b/lib/helpers.nix index 9ff4218..a717ac1 100644 --- a/lib/helpers.nix +++ b/lib/helpers.nix @@ -7,4 +7,6 @@ in { inherit isLinux isDarwin; linuxAttrs = lib.attrsets.optionalAttrs isLinux; darwinAttrs = lib.attrsets.optionalAttrs isDarwin; + mkIfLinux = lib.mkIf isLinux; + mkIfDarwin = lib.mkIf isDarwin; } -- 2.51.2