nix/module/Ollama.nix

66 lines
1.4 KiB
Nix
Raw Normal View History

2024-10-23 19:21:14 +03:00
# SRC: https://github.com/ollama/ollama
{
pkgsStable,
lib,
config,
...
}:
with lib;
let
pkgs = pkgsStable;
cfg = config.module.ollama;
in
{
options = {
module.ollama = {
enable = mkEnableOption "Local LLM server";
primaryModel = mkOption {
default = "llama3.2";
type = types.str;
};
models = mkOption {
default = [ cfg.primaryModel ];
type = types.listOf types.str;
};
};
};
config = mkIf cfg.enable {
environment = {
# Specify default model.
variables.OLLAMA_MODEL = cfg.primaryModel;
};
systemd.services = {
# Enable Ollama server.
ollama = {
description = "Ollama LLM server.";
wantedBy = [ "multi-user.target" ];
serviceConfig.Type = "simple";
script = ''
HOME=/root ${getExe pkgs.ollama} serve
'';
};
# Download Ollama models.
ollama-pull = {
description = "Ollama LLM model.";
wantedBy = [ "multi-user.target" ];
2024-10-23 19:24:53 +03:00
wants = [
"NetworkManager-wait-online.service"
"ollama.service"
];
after = [
"NetworkManager-wait-online.service"
"ollama.service"
];
2024-10-23 19:21:14 +03:00
serviceConfig.Type = "simple";
script = ''
2024-10-23 19:25:43 +03:00
sleep 5
2024-10-23 19:21:14 +03:00
${getExe pkgs.ollama} pull ${concatStringsSep " " cfg.models}
'';
};
};
};
}