refactor: Use mkMerge to combine LLM module configs

This commit is contained in:
Giulio De Pasquale (aider) 2025-06-04 15:44:29 +01:00
parent 317803eb5a
commit 9e8e7169d3

View File

@ -1,7 +1,7 @@
{ config, lib, pkgs, ... }:
let
inherit (lib) mkIf mkEnableOption mkPackageOption mkOption types optionalAttrs;
inherit (lib) mkIf mkEnableOption mkPackageOption mkOption types optionalAttrs mkMerge;
cfg = config.pepe.services.llm;
in
@ -34,7 +34,7 @@ in
};
frontend = {
enable = mkEnableOption "Enable LLM frontend service (Open WebUI)";
enable = mkEnableOption "Enable LLM frontend service (Open WebUI)"; # Defaults to false
uiPackage = mkPackageOption pkgs "open-webui" { };
tikaPackage = mkPackageOption pkgs "tika" { }; # Tika for document processing with Open WebUI
domain = mkOption {
@ -45,10 +45,16 @@ in
};
};
config = mkIf cfg.enable
config = mkMerge [
# Combined environment packages
{
environment.systemPackages = [ cfg.package ];
environment.systemPackages =
(if cfg.enable then [ cfg.package ] else [ ]) ++
(if cfg.enable && cfg.frontend.enable then [ cfg.frontend.uiPackage cfg.frontend.tikaPackage ] else [ ]);
}
# Backend Ollama Service Configuration
(mkIf cfg.enable {
services.ollama = {
enable = true;
package = cfg.package;
@ -73,36 +79,32 @@ in
};
};
};
}
// mkIf (cfg.enable && cfg.frontend.enable) {
environment.systemPackages = [
cfg.frontend.uiPackage
cfg.frontend.tikaPackage
];
})
services = {
open-webui = {
# Frontend Open WebUI and Tika Service Configuration
(mkIf (cfg.enable && cfg.frontend.enable) {
services.open-webui = {
enable = true;
package = cfg.frontend.uiPackage;
};
tika = {
services.tika = {
enable = true;
package = cfg.frontend.tikaPackage;
};
};
pepe.core.vhost.hosts = optionalAttrs (cfg.frontend.domain != null) {
"${cfg.frontend.domain}" = {
locations."/" = {
host = config.services.open-webui.host;
port = config.services.open-webui.port;
allowLAN = true;
allowVPN = true;
allowWAN = true;
proxyWebsockets = true;
pepe.core.vhost.hosts = optionalAttrs (cfg.frontend.domain != null) {
"${cfg.frontend.domain}" = {
locations."/" = {
host = config.services.open-webui.host;
port = config.services.open-webui.port;
allowLAN = true;
allowVPN = true;
allowWAN = true;
proxyWebsockets = true;
};
};
};
};
};
})
];
}