Skip to content

Commit

Permalink
feat: ai ollama module
Browse files Browse the repository at this point in the history
  • Loading branch information
KP64 committed Dec 12, 2024
1 parent 3f3879a commit 243520b
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
16 changes: 13 additions & 3 deletions hosts/kg/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,19 @@
physicalConnections = [ (topology.mkConnectionRev "router" "wifi") ];
};

services.xserver.xkb = {
layout = "de";
variant = "";
services = {
ai.ollama = {
enable = true;
acceleration = "cuda";
models = [
"llama3.2"
"llama3.1:8b"
];
};
xserver.xkb = {
layout = "de";
variant = "";
};
};

time.timeZone = "Europe/Berlin";
Expand Down
1 change: 1 addition & 0 deletions services/ai/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ imports = [ ./ollama.nix ]; }
45 changes: 45 additions & 0 deletions services/ai/ollama.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{ config, lib, ... }:
let
cfg = config.services.ai.ollama;
in
{
options.services.ai.ollama = {
enable = lib.mkEnableOption "Ollama";

acceleration = lib.mkOption {
readOnly = true;
type = lib.types.enum [
"cpu"
"cuda"
"rocm"
];
example = "cpu";
description = "Whether to use the GPU or CPU";
};

models = lib.mkOption {
readOnly = true;
type = with lib.types; nonEmptyListOf nonEmptyStr;
example = [
"llama3.1"
"llama3.2:1b"
];
description = "The models to be automatically downloaded.";
};
};

config = lib.mkMerge [
(lib.mkIf cfg.enable {
services.ollama = {
enable = true;
openFirewall = true;
inherit (cfg) acceleration;
loadModels = cfg.models;
};
})

(lib.mkIf config.system.impermanence.enable {
environment.persistence."/persist".directories = lib.optional cfg.enable "/var/lib/private/ollama";
})
];
}
1 change: 1 addition & 0 deletions services/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
imports = [
./ai
./gaming
./networking
];
Expand Down

0 comments on commit 243520b

Please sign in to comment.