-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #316248 from shivaraj-bh/open-webui
open-webui: init at 0.2.4
- Loading branch information
Showing
5 changed files
with
271 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
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,94 @@ | ||
{ | ||
config, | ||
lib, | ||
pkgs, | ||
... | ||
}: | ||
let | ||
inherit (lib) types; | ||
|
||
cfg = config.services.open-webui; | ||
in | ||
{ | ||
options = { | ||
services.open-webui = { | ||
enable = lib.mkEnableOption "Enable open-webui, an interactive chat web app"; | ||
package = lib.mkPackageOption pkgs "open-webui" { }; | ||
|
||
stateDir = lib.mkOption { | ||
type = types.path; | ||
default = "/var/lib/open-webui"; | ||
description = "State directory of open-webui."; | ||
}; | ||
|
||
host = lib.mkOption { | ||
type = types.str; | ||
default = "localhost"; | ||
description = "Host of open-webui"; | ||
}; | ||
|
||
port = lib.mkOption { | ||
type = types.port; | ||
default = 8080; | ||
description = "Port of open-webui"; | ||
}; | ||
|
||
environment = lib.mkOption { | ||
type = types.attrsOf types.str; | ||
default = { }; | ||
example = '' | ||
{ | ||
OLLAMA_API_BASE_URL = "http://localhost:11434"; | ||
# Disable authentication | ||
WEBUI_AUTH = "False"; | ||
} | ||
''; | ||
description = "Extra environment variables for open-webui"; | ||
}; | ||
}; | ||
}; | ||
|
||
config = lib.mkIf cfg.enable { | ||
systemd.services.open-webui = { | ||
description = "User-friendly WebUI for LLMs (Formerly Ollama WebUI)"; | ||
wantedBy = [ "multi-user.target" ]; | ||
after = [ "network.target" ]; | ||
|
||
preStart = '' | ||
mkdir -p ${cfg.stateDir}/static | ||
''; | ||
|
||
environment = { | ||
STATIC_DIR = "${cfg.stateDir}/static"; | ||
DATA_DIR = "${cfg.stateDir}"; | ||
} // cfg.environment; | ||
|
||
serviceConfig = { | ||
ExecStart = "${lib.getExe cfg.package} serve --host ${cfg.host} --port ${toString cfg.port}"; | ||
WorkingDirectory = cfg.stateDir; | ||
StateDirectory = "open-webui"; | ||
RuntimeDirectory = "open-webui"; | ||
RuntimeDirectoryMode = "0755"; | ||
PrivateTmp = true; | ||
DynamicUser = true; | ||
DevicePolicy = "closed"; | ||
LockPersonality = true; | ||
MemoryDenyWriteExecute = false; # onnxruntime/capi/onnxruntime_pybind11_state.so: cannot enable executable stack as shared object requires: Permission Denied | ||
PrivateUsers = true; | ||
ProtectHome = true; | ||
ProtectHostname = true; | ||
ProtectKernelLogs = true; | ||
ProtectKernelModules = true; | ||
ProtectKernelTunables = true; | ||
ProtectControlGroups = true; | ||
ProcSubset = "all"; # Error in cpuinfo: failed to parse processor information from /proc/cpuinfo | ||
RestrictNamespaces = true; | ||
RestrictRealtime = true; | ||
SystemCallArchitectures = "native"; | ||
UMask = "0077"; | ||
}; | ||
}; | ||
}; | ||
|
||
meta.maintainers = with lib.maintainers; [ shivaraj-bh ]; | ||
} |
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
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,33 @@ | ||
{ lib, ... }: | ||
let | ||
mainPort = "8080"; | ||
in | ||
{ | ||
name = "open-webui"; | ||
meta = with lib.maintainers; { | ||
maintainers = [ shivaraj-bh ]; | ||
}; | ||
|
||
nodes = { | ||
machine = | ||
{ ... }: | ||
{ | ||
services.open-webui = { | ||
enable = true; | ||
environment = { | ||
# Requires network connection | ||
RAG_EMBEDDING_MODEL = ""; | ||
}; | ||
}; | ||
}; | ||
}; | ||
|
||
testScript = '' | ||
machine.start() | ||
machine.wait_for_unit("open-webui.service") | ||
machine.wait_for_open_port(${mainPort}) | ||
machine.succeed("curl http://127.0.0.1:${mainPort}") | ||
''; | ||
} |
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,142 @@ | ||
{ | ||
lib, | ||
buildNpmPackage, | ||
fetchFromGitHub, | ||
python3, | ||
nixosTests, | ||
}: | ||
let | ||
pname = "open-webui"; | ||
version = "0.2.4"; | ||
|
||
src = fetchFromGitHub { | ||
owner = "open-webui"; | ||
repo = "open-webui"; | ||
rev = "v${version}"; | ||
hash = "sha256-jWO0mo26C+QTIX5j3ucDk/no+vQnAh7Q6JwB3lLM83k="; | ||
}; | ||
|
||
frontend = buildNpmPackage { | ||
inherit pname version src; | ||
|
||
npmDepsHash = "sha256-QIgYHZusuq2QD8p8MGsNVhCbz6fR+qP9UuU/kbBkadc="; | ||
|
||
# Disabling `pyodide:fetch` as it downloads packages during `buildPhase` | ||
# Until this is solved, running python packages from the browser will not work. | ||
postPatch = '' | ||
substituteInPlace package.json \ | ||
--replace-fail "npm run pyodide:fetch && vite build" "vite build" \ | ||
''; | ||
|
||
env.CYPRESS_INSTALL_BINARY = "0"; # disallow cypress from downloading binaries in sandbox | ||
|
||
installPhase = '' | ||
runHook preInstall | ||
mkdir -p $out/share | ||
cp -a build $out/share/open-webui | ||
runHook postInstall | ||
''; | ||
}; | ||
in | ||
python3.pkgs.buildPythonApplication rec { | ||
inherit pname version src; | ||
pyproject = true; | ||
|
||
# The custom hook tries to run `npm install` in `buildPhase`. | ||
# We don't have to worry, as nodejs depedencies are managed by `frontend` drv. | ||
postPatch = '' | ||
substituteInPlace pyproject.toml \ | ||
--replace-fail '[tool.hatch.build.hooks.custom]' "" \ | ||
--replace-fail ', build = "open_webui/frontend"' "" | ||
''; | ||
|
||
pythonRelaxDeps = true; | ||
|
||
pythonRemoveDeps = [ | ||
# using `psycopg2` instead | ||
"psycopg2-binary" | ||
# using `opencv4` | ||
"opencv-python-headless" | ||
# package request: https://github.com/NixOS/nixpkgs/issues/317065 | ||
"rapidocr-onnxruntime" | ||
# package request: https://github.com/NixOS/nixpkgs/issues/317066 | ||
"langfuse" | ||
# package request: https://github.com/NixOS/nixpkgs/issues/317068 | ||
"langchain-chroma" | ||
]; | ||
|
||
dependencies = with python3.pkgs; [ | ||
beautifulsoup4 | ||
fastapi | ||
uvicorn | ||
python-multipart | ||
flask | ||
flask-cors | ||
python-socketio | ||
python-jose | ||
passlib | ||
requests | ||
aiohttp | ||
peewee | ||
peewee-migrate | ||
psycopg2 | ||
pymysql | ||
bcrypt | ||
litellm | ||
boto3 | ||
argon2-cffi | ||
apscheduler | ||
google-generativeai | ||
langchain | ||
langchain-community | ||
fake-useragent | ||
chromadb | ||
sentence-transformers | ||
pypdf | ||
docx2txt | ||
python-pptx | ||
unstructured | ||
markdown | ||
pypandoc | ||
pandas | ||
openpyxl | ||
pyxlsb | ||
xlrd | ||
validators | ||
opencv4 | ||
fpdf2 | ||
rank-bm25 | ||
faster-whisper | ||
pyjwt | ||
black | ||
youtube-transcript-api | ||
pytube | ||
]; | ||
|
||
build-system = with python3.pkgs; [ | ||
hatchling | ||
pythonRelaxDepsHook | ||
]; | ||
|
||
pythonImportsCheck = [ "open_webui" ]; | ||
|
||
postInstall = '' | ||
wrapProgram $out/bin/open-webui \ | ||
--set FRONTEND_BUILD_DIR "${frontend}/share/open-webui" | ||
''; | ||
|
||
passthru.tests = { | ||
inherit (nixosTests) open-webui; | ||
}; | ||
|
||
meta = { | ||
description = "Full-stack of open-webui. open-webui is a user-friendly WebUI for LLMs (Formerly Ollama WebUI)"; | ||
homepage = "https://github.com/open-webui/open-webui"; | ||
changelog = "https://github.com/open-webui/open-webui/blob/${src.rev}/CHANGELOG.md"; | ||
license = lib.licenses.mit; | ||
maintainers = with lib.maintainers; [ shivaraj-bh ]; | ||
mainProgram = "open-webui"; | ||
}; | ||
} |