-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
efa9010
commit b5108fa
Showing
4 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
|
||
[comment]: # (Please add your documentation on top of this line) | ||
|
||
@AUTOGEN_OPTIONS@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ pkgs, ... }: | ||
|
||
{ | ||
packages = [ pkgs.coreutils ]; | ||
services.ollama = { | ||
enable = true; | ||
address = "0.0.0.0"; | ||
port = 11434; | ||
# acceleration = ""; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
{ config | ||
, lib | ||
, pkgs | ||
, ... | ||
}: | ||
|
||
with lib; | ||
|
||
let | ||
cfg = config.services.ollama; | ||
inherit (lib) types; | ||
|
||
ollamaPackage = cfg.package.override { inherit (cfg) acceleration; }; | ||
in | ||
{ | ||
options = { | ||
services.ollama = { | ||
enable = mkEnableOption "ollama"; | ||
package = lib.mkPackageOption pkgs "ollama" { }; | ||
|
||
address = lib.mkOption { | ||
type = types.str; | ||
default = "127.0.0.1"; | ||
example = "[::]"; | ||
description = '' | ||
The host address which the ollama server HTTP interface listens to. | ||
''; | ||
}; | ||
|
||
port = lib.mkOption { | ||
type = types.port; | ||
default = 11434; | ||
example = 11111; | ||
description = '' | ||
Which port the ollama server listens to. | ||
''; | ||
}; | ||
|
||
acceleration = lib.mkOption { | ||
type = types.nullOr ( | ||
types.enum [ | ||
false | ||
"rocm" | ||
"cuda" | ||
] | ||
); | ||
default = null; | ||
example = "rocm"; | ||
description = '' | ||
What interface to use for hardware acceleration. | ||
- `null`: default behavior | ||
- if `nixpkgs.config.rocmSupport` is enabled, uses `"rocm"` | ||
- if `nixpkgs.config.cudaSupport` is enabled, uses `"cuda"` | ||
- otherwise defaults to `false` | ||
- `false`: disable GPU, only use CPU | ||
- `"rocm"`: supported by most modern AMD GPUs | ||
- may require overriding gpu type with `services.ollama.rocmOverrideGfx` | ||
if rocm doesn't detect your AMD gpu | ||
- `"cuda"`: supported by most modern NVIDIA GPUs | ||
''; | ||
}; | ||
}; | ||
}; | ||
|
||
config = lib.mkIf cfg.enable { | ||
env = { | ||
OLLAMA_HOST = "${cfg.address}:${toString cfg.port}"; | ||
}; | ||
|
||
processes.ollama = { | ||
exec = "${lib.getExe ollamaPackage} serve"; | ||
|
||
process-compose = { | ||
readiness_probe = { | ||
exec.command = "${pkgs.curl}/bin/curl -f -k ${cfg.address}:${toString cfg.port}"; | ||
initial_delay_seconds = 2; | ||
period_seconds = 10; | ||
timeout_seconds = 2; | ||
success_threshold = 1; | ||
failure_threshold = 5; | ||
}; | ||
|
||
availability.restart = "on_failure"; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
services.ollama = { | ||
enable = true; | ||
address = "0.0.0.0"; | ||
port = 11434; | ||
}; | ||
} |