1
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-06-23 01:41:05 +03:00
nixpkgs/nixos/modules/services/misc/ollama.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
1.8 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
let
inherit (lib) types;
2023-12-29 01:46:01 +01:00
cfg = config.services.ollama;
ollamaPackage = cfg.package.override {
inherit (cfg) acceleration;
linuxPackages = config.boot.kernelPackages.overrideAttrs {
nvidia_x11 = config.hardware.nvidia.package;
};
};
in
{
2023-12-29 01:46:01 +01:00
options = {
services.ollama = {
enable = lib.mkEnableOption (
lib.mdDoc "Server for local large language models"
);
2024-01-20 14:36:55 +01:00
listenAddress = lib.mkOption {
type = types.str;
2024-01-20 14:36:55 +01:00
default = "127.0.0.1:11434";
description = lib.mdDoc ''
Specifies the bind address on which the ollama server HTTP interface listens.
'';
};
acceleration = lib.mkOption {
type = types.nullOr (types.enum [ "rocm" "cuda" ]);
default = null;
example = "rocm";
description = lib.mdDoc ''
Specifies the interface to use for hardware acceleration.
- `rocm`: supported by modern AMD GPUs
- `cuda`: supported by modern NVIDIA GPUs
'';
};
2023-12-29 01:46:01 +01:00
package = lib.mkPackageOption pkgs "ollama" { };
};
};
config = lib.mkIf cfg.enable {
systemd = {
services.ollama = {
wantedBy = [ "multi-user.target" ];
description = "Server for local large language models";
after = [ "network.target" ];
environment = {
HOME = "%S/ollama";
OLLAMA_MODELS = "%S/ollama/models";
2024-01-20 14:36:55 +01:00
OLLAMA_HOST = cfg.listenAddress;
2023-12-29 01:46:01 +01:00
};
serviceConfig = {
ExecStart = "${lib.getExe ollamaPackage} serve";
2023-12-29 01:46:01 +01:00
WorkingDirectory = "/var/lib/ollama";
StateDirectory = [ "ollama" ];
DynamicUser = true;
};
};
};
environment.systemPackages = [ ollamaPackage ];
2023-12-29 01:46:01 +01:00
};
meta.maintainers = with lib.maintainers; [ abysssol onny ];
2023-12-29 01:46:01 +01:00
}