2024-10-23 19:21:14 +03:00
|
|
|
# SRC: https://github.com/ollama/ollama
|
|
|
|
{
|
2024-11-04 04:37:29 +03:00
|
|
|
pkgsUnstable,
|
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
util,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
cfg = config.module.ollama;
|
|
|
|
in {
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
# Specify default model.
|
|
|
|
environment.variables.OLLAMA_MODEL = cfg.primaryModel;
|
2024-10-23 19:21:14 +03:00
|
|
|
|
2024-11-04 04:37:29 +03:00
|
|
|
systemd.services = {
|
|
|
|
# Enable Ollama server.
|
|
|
|
ollama = {
|
|
|
|
description = "Ollama LLM server";
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
};
|
|
|
|
wantedBy = [
|
|
|
|
"multi-user.target"
|
|
|
|
];
|
|
|
|
script = ''
|
|
|
|
HOME=/root ${lib.getExe pkgsUnstable.ollama} serve
|
|
|
|
'';
|
|
|
|
};
|
2024-10-23 19:21:14 +03:00
|
|
|
|
2024-11-04 04:37:29 +03:00
|
|
|
# Download Ollama models.
|
|
|
|
ollama-pull = {
|
|
|
|
description = "Ollama LLM model";
|
|
|
|
after = [
|
|
|
|
"NetworkManager-wait-online.service"
|
|
|
|
"ollama.service"
|
|
|
|
];
|
|
|
|
wantedBy = [
|
|
|
|
"multi-user.target"
|
|
|
|
];
|
|
|
|
wants = [
|
|
|
|
"NetworkManager-wait-online.service"
|
|
|
|
"ollama.service"
|
|
|
|
];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
};
|
|
|
|
script = util.trimTabs ''
|
|
|
|
sleep 5
|
|
|
|
${lib.getExe pkgsUnstable.ollama} pull ${lib.concatStringsSep " " cfg.models}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-10-23 19:21:14 +03:00
|
|
|
}
|