nixos/ollama: add option for hardware acceleration
This commit is contained in:
parent
70e834c19b
commit
b8d8c1f207
1 changed files with 23 additions and 10 deletions
|
@ -1,9 +1,14 @@
|
|||
{ config, lib, pkgs, ... }: let
|
||||
{ config, lib, pkgs, ... }:
|
||||
let
|
||||
inherit (lib.types) nullOr enum;
|
||||
|
||||
cfg = config.services.ollama;
|
||||
|
||||
in {
|
||||
|
||||
ollamaPackage = cfg.package.override {
|
||||
inherit (cfg) acceleration;
|
||||
linuxPackages.nvidia_x11 = config.hardware.nvidia.package;
|
||||
};
|
||||
in
|
||||
{
|
||||
options = {
|
||||
services.ollama = {
|
||||
enable = lib.mkEnableOption (
|
||||
|
@ -16,12 +21,22 @@ in {
|
|||
Specifies the bind address on which the ollama server HTTP interface listens.
|
||||
'';
|
||||
};
|
||||
acceleration = lib.mkOption {
|
||||
type = nullOr (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
|
||||
'';
|
||||
};
|
||||
package = lib.mkPackageOption pkgs "ollama" { };
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
|
||||
systemd = {
|
||||
services.ollama = {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
|
@ -33,7 +48,7 @@ in {
|
|||
OLLAMA_HOST = cfg.listenAddress;
|
||||
};
|
||||
serviceConfig = {
|
||||
ExecStart = "${lib.getExe cfg.package} serve";
|
||||
ExecStart = "${lib.getExe ollamaPackage} serve";
|
||||
WorkingDirectory = "/var/lib/ollama";
|
||||
StateDirectory = [ "ollama" ];
|
||||
DynamicUser = true;
|
||||
|
@ -41,10 +56,8 @@ in {
|
|||
};
|
||||
};
|
||||
|
||||
environment.systemPackages = [ cfg.package ];
|
||||
|
||||
environment.systemPackages = [ ollamaPackage ];
|
||||
};
|
||||
|
||||
meta.maintainers = with lib.maintainers; [ onny ];
|
||||
|
||||
meta.maintainers = with lib.maintainers; [ abysssol onny ];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue