diff --git a/modules/services/default.nix b/modules/services/default.nix index 40aba48..e2bce56 100644 --- a/modules/services/default.nix +++ b/modules/services/default.nix @@ -7,11 +7,13 @@ ./jellyfin ./jellyseer ./lidarr + ./llm ./minio ./navidrome ./nzbget ./prowlarr ./radarr + ./redlib ./sonarr ]; } diff --git a/modules/services/llm/default.nix b/modules/services/llm/default.nix new file mode 100644 index 0000000..7ff5025 --- /dev/null +++ b/modules/services/llm/default.nix @@ -0,0 +1,87 @@ +{ config, lib, pkgs, ... }: + +let + inherit (lib) mkIf; + + cfg = config.pepe.services.llm; +in +{ + options.pepe.services.llm = with lib; { + enable = mkEnableOption "Enable LLM services (Ollama and Open WebUI)"; + package = mkPackageOption pkgs "ollama" { }; + uiPackage = mkPackageOption pkgs "open-webui" { }; + tikaPackage = mkPackageOption pkgs "tika" { }; + backendDomain = mkOption { + type = types.str; + default = null; + }; + frontendDomain = mkOption { + type = types.str; + default = null; + }; + acceleration = mkOption { + type = types.enum [ "none" "cuda" "rocm" ]; + default = "none"; + description = "Acceleration type for Ollama"; + }; + environmentVariables = mkOption { + type = types.attrsOf types.str; + default = { + OLLAMA_FLASH_ATTENTION = "1"; + OLLAMA_NUM_PARALLEL = "2"; + OLLAMA_KV_CACHE_TYPE = "q8_0"; + }; + description = "Environment variables for Ollama"; + }; + }; + + config = mkIf cfg.enable { + environment.systemPackages = [ cfg.package ]; + + services = { + ollama = { + enable = true; + package = cfg.package; + acceleration = cfg.acceleration; + environmentVariables = cfg.environmentVariables; + }; + + open-webui = { + enable = true; + package = cfg.uiPackage; + }; + + tika = { + enable = true; + package = cfg.tikaPackage; + }; + }; + + pepe.core.vhost.hosts.${cfg.backendDomain} = { + locations."/" = { + host = config.services.ollama.host; + port = config.services.ollama.port; + allowLAN = true; + allowVPN = true; + allowWAN = true; + recommendedProxySettings = false; + extraConfig = '' + proxy_buffering off; + proxy_read_timeout 600s; + proxy_set_header Host localhost:${toString config.services.ollama.port}; + ''; + }; + }; + + pepe.core.vhost.hosts.${cfg.frontendDomain} = { + locations."/" = { + host = config.services.open-webui.host; + port = config.services.open-webui.port; + allowLAN = true; + allowVPN = true; + allowWAN = true; + proxyWebsockets = true; + }; + }; + }; +} diff --git a/modules/services/redlib/default.nix b/modules/services/redlib/default.nix new file mode 100644 index 0000000..4806e52 --- /dev/null +++ b/modules/services/redlib/default.nix @@ -0,0 +1,48 @@ +{ config, lib, pkgs, ... }: + +let + inherit (lib) mkIf; + + cfg = config.pepe.services.redlib; +in +{ + options.pepe.services.redlib = with lib; { + enable = mkEnableOption "Enable Redlib"; + package = mkPackageOption pkgs "redlib" { }; + domain = mkOption { + type = types.str; + default = null; + }; + settings = mkOption { + type = types.attrsOf types.str; + default = { + REDLIB_ROBOTS_DISABLE_INDEXING = "on"; + REDLIB_DEFAULT_THEME = "dracula"; + REDLIB_DEFAULT_SHOW_NSFW = "on"; + REDLIB_DEFAULT_BLUR_NSFW = "off"; + REDLIB_DEFAULT_USE_HLS = "on"; + REDLIB_DEFAULT_HIDE_HLS_NOTIFICATION = "on"; + }; + description = "Environment variables for Redlib configuration"; + }; + }; + + config = mkIf cfg.enable { + services.redlib = { + enable = true; + port = 9090; + package = cfg.package; + }; + + systemd.services.redlib.environment = cfg.settings; + + pepe.core.vhost.hosts.${cfg.domain} = { + locations."/" = { + port = config.services.redlib.port; + allowLAN = true; + allowVPN = true; + allowWAN = true; + }; + }; + }; +}