fix: Trying to fix ollama service for darwin

This commit is contained in:
uttarayan21
2025-02-21 15:12:22 +05:30
parent a10ca460df
commit 9a69580cf6
5 changed files with 118 additions and 3 deletions

View File

@@ -3,5 +3,6 @@
./yabai.nix ./yabai.nix
./skhd.nix ./skhd.nix
./tailscale.nix ./tailscale.nix
./ollama.nix
]; ];
} }

View File

@@ -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 = "*";
};
};
}

View File

@@ -73,7 +73,7 @@
then "open" then "open"
else "xdg-open"; else "xdg-open";
}; };
sessionPath = ["${config.home.homeDirectory}/.cargo/bin"]; sessionPath = ["${config.home.homeDirectory}/.cargo/bin" "${config.home.homeDirectory}/.local/bin"];
stateVersion = "23.11"; stateVersion = "23.11";
}; };

View File

@@ -1,13 +1,12 @@
set dotenv-load set dotenv-load
# clean := `git diff-index --quiet --cached HEAD --`
[macos] [macos]
install: install:
nix run nix-darwin -- switch --flake . nix run nix-darwin -- switch --flake .
[linux] [linux]
install: install:
NIX_BUILD_CORES=0 sudo nixos-rebuild switch --flake . sudo nixos-rebuild switch --flake .
[macos] [macos]
build: build:

98
modules/ollama.nix Normal file
View File

@@ -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}
# '';
};
}