refactor: Restructure LLM module options and vhost creation
This commit is contained in:
parent
46cb8d1c7e
commit
317803eb5a
@ -1,29 +1,28 @@
|
|||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (lib) mkIf;
|
inherit (lib) mkIf mkEnableOption mkPackageOption mkOption types optionalAttrs;
|
||||||
|
|
||||||
cfg = config.pepe.services.llm;
|
cfg = config.pepe.services.llm;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.pepe.services.llm = with lib; {
|
options.pepe.services.llm = {
|
||||||
enable = mkEnableOption "Enable LLM services (Ollama and Open WebUI)";
|
enable = mkEnableOption "Enable LLM backend service (Ollama)";
|
||||||
|
|
||||||
package = mkPackageOption pkgs "ollama" { };
|
package = mkPackageOption pkgs "ollama" { };
|
||||||
uiPackage = mkPackageOption pkgs "open-webui" { };
|
|
||||||
tikaPackage = mkPackageOption pkgs "tika" { };
|
|
||||||
backendDomain = mkOption {
|
backendDomain = mkOption {
|
||||||
type = types.str;
|
type = types.nullOr types.str;
|
||||||
default = null;
|
|
||||||
};
|
|
||||||
frontendDomain = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
default = null;
|
default = null;
|
||||||
|
description = "Domain for Ollama backend. If null, no vhost is created for the backend.";
|
||||||
};
|
};
|
||||||
|
|
||||||
acceleration = mkOption {
|
acceleration = mkOption {
|
||||||
type = types.enum [ "none" "cuda" "rocm" ];
|
type = types.enum [ "none" "cuda" "rocm" ];
|
||||||
default = "none";
|
default = "none";
|
||||||
description = "Acceleration type for Ollama";
|
description = "Acceleration type for Ollama";
|
||||||
};
|
};
|
||||||
|
|
||||||
environmentVariables = mkOption {
|
environmentVariables = mkOption {
|
||||||
type = types.attrsOf types.str;
|
type = types.attrsOf types.str;
|
||||||
default = {
|
default = {
|
||||||
@ -33,31 +32,32 @@ in
|
|||||||
};
|
};
|
||||||
description = "Environment variables for Ollama";
|
description = "Environment variables for Ollama";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
frontend = {
|
||||||
|
enable = mkEnableOption "Enable LLM frontend service (Open WebUI)";
|
||||||
|
uiPackage = mkPackageOption pkgs "open-webui" { };
|
||||||
|
tikaPackage = mkPackageOption pkgs "tika" { }; # Tika for document processing with Open WebUI
|
||||||
|
domain = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
description = "Domain for Open WebUI frontend. If null, no vhost is created for the frontend.";
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable
|
||||||
|
{
|
||||||
environment.systemPackages = [ cfg.package ];
|
environment.systemPackages = [ cfg.package ];
|
||||||
|
|
||||||
services = {
|
services.ollama = {
|
||||||
ollama = {
|
|
||||||
enable = true;
|
enable = true;
|
||||||
package = cfg.package;
|
package = cfg.package;
|
||||||
acceleration = cfg.acceleration;
|
acceleration = cfg.acceleration;
|
||||||
environmentVariables = cfg.environmentVariables;
|
environmentVariables = cfg.environmentVariables;
|
||||||
};
|
};
|
||||||
|
|
||||||
open-webui = {
|
pepe.core.vhost.hosts = optionalAttrs (cfg.backendDomain != null) {
|
||||||
enable = true;
|
"${cfg.backendDomain}" = {
|
||||||
package = cfg.uiPackage;
|
|
||||||
};
|
|
||||||
|
|
||||||
tika = {
|
|
||||||
enable = true;
|
|
||||||
package = cfg.tikaPackage;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
pepe.core.vhost.hosts.${cfg.backendDomain} = {
|
|
||||||
locations."/" = {
|
locations."/" = {
|
||||||
host = config.services.ollama.host;
|
host = config.services.ollama.host;
|
||||||
port = config.services.ollama.port;
|
port = config.services.ollama.port;
|
||||||
@ -67,13 +67,33 @@ in
|
|||||||
recommendedProxySettings = false;
|
recommendedProxySettings = false;
|
||||||
extraConfig = ''
|
extraConfig = ''
|
||||||
proxy_buffering off;
|
proxy_buffering off;
|
||||||
proxy_read_timeout 600s;
|
proxy_read_timeout 600s; # Ollama can take time to respond
|
||||||
proxy_set_header Host localhost:${toString config.services.ollama.port};
|
proxy_set_header Host localhost:${toString config.services.ollama.port};
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// mkIf (cfg.enable && cfg.frontend.enable) {
|
||||||
|
environment.systemPackages = [
|
||||||
|
cfg.frontend.uiPackage
|
||||||
|
cfg.frontend.tikaPackage
|
||||||
|
];
|
||||||
|
|
||||||
pepe.core.vhost.hosts.${cfg.frontendDomain} = {
|
services = {
|
||||||
|
open-webui = {
|
||||||
|
enable = true;
|
||||||
|
package = cfg.frontend.uiPackage;
|
||||||
|
};
|
||||||
|
|
||||||
|
tika = {
|
||||||
|
enable = true;
|
||||||
|
package = cfg.frontend.tikaPackage;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
pepe.core.vhost.hosts = optionalAttrs (cfg.frontend.domain != null) {
|
||||||
|
"${cfg.frontend.domain}" = {
|
||||||
locations."/" = {
|
locations."/" = {
|
||||||
host = config.services.open-webui.host;
|
host = config.services.open-webui.host;
|
||||||
port = config.services.open-webui.port;
|
port = config.services.open-webui.port;
|
||||||
@ -84,4 +104,5 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user