diff --git a/darwin/kuro/services/default.nix b/darwin/kuro/services/default.nix index b99c8d34..ee7241e6 100644 --- a/darwin/kuro/services/default.nix +++ b/darwin/kuro/services/default.nix @@ -3,5 +3,6 @@ ./yabai.nix ./skhd.nix ./tailscale.nix + ./ollama.nix ]; } diff --git a/darwin/kuro/services/ollama.nix b/darwin/kuro/services/ollama.nix new file mode 100644 index 00000000..5058ac65 --- /dev/null +++ b/darwin/kuro/services/ollama.nix @@ -0,0 +1,17 @@ +{pkgs, ...}: { + imports = [../../../modules/ollama.nix]; + services.ollama = { + enable = true; + host = "127.0.0.1"; + port = 11434; + loadModels = [ + "deepseek-r1:7b" + # "deepseek-r1:14b" + # "RobinBially/nomic-embed-text-8k" + ]; + environmentVariables = { + OLLAMA_ORIGINS = "*"; + }; + }; +} + diff --git a/home/default.nix b/home/default.nix index b198cb9d..b331afa1 100644 --- a/home/default.nix +++ b/home/default.nix @@ -73,7 +73,7 @@ then "open" else "xdg-open"; }; - sessionPath = ["${config.home.homeDirectory}/.cargo/bin"]; + sessionPath = ["${config.home.homeDirectory}/.cargo/bin" "${config.home.homeDirectory}/.local/bin"]; stateVersion = "23.11"; }; diff --git a/justfile b/justfile index 7a63c266..513bd386 100644 --- a/justfile +++ b/justfile @@ -1,13 +1,12 @@ set dotenv-load -# clean := `git diff-index --quiet --cached HEAD --` [macos] install: nix run nix-darwin -- switch --flake . [linux] install: - NIX_BUILD_CORES=0 sudo nixos-rebuild switch --flake . + sudo nixos-rebuild switch --flake . [macos] build: diff --git a/modules/ollama.nix b/modules/ollama.nix new file mode 100644 index 00000000..4c1a6c71 --- /dev/null +++ b/modules/ollama.nix @@ -0,0 +1,98 @@ +{ + config, + lib, + pkgs, + ... +}: +with lib; let + cfg = config.services.ollama; +in { + options = { + services.ollama = { + enable = mkEnableOption "Ollama AI model runner"; + + package = mkOption { + type = types.package; + default = pkgs.ollama; + defaultText = literalExpression "pkgs.ollama"; + description = "The ollama package to use."; + }; + + host = mkOption { + type = types.str; + default = "127.0.0.1"; + description = "The host address to listen on."; + }; + + port = mkOption { + type = types.port; + default = 11434; + description = "The port to listen on."; + }; + + environmentVariables = mkOption { + type = types.attrs; + default = {}; + description = "Environment variables to set for the Ollama service."; + }; + + loadModels = mkOption { + type = types.listOf types.str; + default = []; + description = "List of models to load on startup."; + }; + + dataDir = mkOption { + type = types.path; + default = "/var/lib/ollama"; + description = "Directory to store Ollama data."; + }; + }; + }; + + config = mkIf cfg.enable { + # users.users.ollama = { + # name = "ollama"; + # uid = 601; + # gid = config.users.groups.ollama.gid; + # home = cfg.dataDir; + # createHome = true; + # description = "Ollama service user"; + # }; + # + # users.groups.ollama = { + # name = "ollama"; + # gid = 602; + # }; + + launchd.daemons.ollama = { + path = [cfg.package]; + command = "${cfg.package}/bin/ollama serve"; + serviceConfig = { + Label = "com.ollama.service"; + # ProgramArguments = ["serve"]; + # WorkingDirectory = cfg.dataDir; + EnvironmentVariables = + { + OLLAMA_HOST = cfg.host; + OLLAMA_PORT = toString cfg.port; + } + // cfg.environmentVariables; + RunAtLoad = true; + KeepAlive = true; + # StandardOutPath = "/var/log/ollama.log"; + # StandardErrorPath = "/var/log/ollama.error.log"; + # UserName = "ollama"; + # GroupName = "ollama"; + }; + }; + + # system.activationScripts.preActivation.text = mkIf (cfg.loadModels != []) '' + # # Load Ollama models + # ${concatMapStrings (model: '' + # ${cfg.package}/bin/ollama pull ${model} + # '') + # cfg.loadModels} + # ''; + }; +}