From 029cd3f268b87be3b0ea3b1e29b2499de4971a59 Mon Sep 17 00:00:00 2001 From: DannyDannyDanny Date: Sun, 26 Oct 2025 19:48:17 +0100 Subject: [PATCH] feat: add ollama :sparkles: :poop: --- nixos/hosts/macos.nix | 6 +++ nixos/ollama.nix | 92 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 nixos/ollama.nix diff --git a/nixos/hosts/macos.nix b/nixos/hosts/macos.nix index b14a605..8d2ca38 100644 --- a/nixos/hosts/macos.nix +++ b/nixos/hosts/macos.nix @@ -17,6 +17,12 @@ programs.direnv.enable = true; programs.direnv.nix-direnv.enable = true; + # ollama + imports = [../ollama.nix]; + services.ollama = { + enable = true; + }; + # Networking (macOS-safe) networking = { # Set if you want a specific hostname in macOS UI as well: diff --git a/nixos/ollama.nix b/nixos/ollama.nix new file mode 100644 index 0000000..ebf0d1b --- /dev/null +++ b/nixos/ollama.nix @@ -0,0 +1,92 @@ +# src: https://github.com/nix-darwin/nix-darwin/pull/972 +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.services.ollama; + +in { + meta.maintainers = [ "velnbur" ]; + + options = { + services.ollama = { + enable = mkOption { + type = types.bool; + default = false; + description = "Whether to enable the Ollama Daemon."; + }; + + package = mkOption { + type = types.path; + default = pkgs.ollama; + description = "This option specifies the ollama package to use."; + }; + + host = mkOption { + type = types.str; + default = "127.0.0.1"; + example = "0.0.0.0"; + description = '' + The host address which the ollama server HTTP interface listens to. + ''; + }; + + port = mkOption { + type = types.port; + default = 11434; + example = 11111; + description = '' + Which port the ollama server listens to. + ''; + }; + + models = mkOption { + type = types.nullOr types.str; + default = null; + example = "/path/to/ollama/models"; + description = '' + The directory that the ollama service will read models from and download new models to. + ''; + }; + + environmentVariables = mkOption { + type = types.attrsOf types.str; + default = { }; + example = { + OLLAMA_LLM_LIBRARY = "cpu"; + HIP_VISIBLE_DEVICES = "0,1"; + }; + description = '' + Set arbitrary environment variables for the ollama service. + + Be aware that these are only seen by the ollama server (launchd daemon), + not normal invocations like `ollama run`. + Since `ollama run` is mostly a shell around the ollama server, this is usually sufficient. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + + environment.systemPackages = [ cfg.package ]; + + launchd.user.agents.ollama = { + path = [ config.environment.systemPath ]; + + serviceConfig = { + KeepAlive = true; + RunAtLoad = true; + ProgramArguments = [ "${cfg.package}/bin/ollama" "serve" ]; + + EnvironmentVariables = cfg.environmentVariables // { + OLLAMA_HOST = "${cfg.host}:${toString cfg.port}"; + } // (optionalAttrs (cfg.models != null) { + OLLAMA_MODELS = cfg.models; + }); + }; + }; + }; +}