Skip to content

Commit

Permalink
feat(open-webui): init
Browse files Browse the repository at this point in the history
  • Loading branch information
shivaraj-bh committed Jun 11, 2024
1 parent 3e68d66 commit 399b858
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
1 change: 1 addition & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ in
./mysql
./nginx
./postgres
./open-webui.nix
./redis-cluster.nix
./redis.nix
./zookeeper.nix
Expand Down
95 changes: 95 additions & 0 deletions nix/open-webui.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Based on: https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/misc/open-webui.nix
{ pkgs, lib, name, config, ... }:
let
inherit (lib) types;
in
{
options = {
enable = lib.mkEnableOption "Open-WebUI server";
package = lib.mkPackageOption pkgs "open-webui" { };

dataDir = lib.mkOption {
type = types.str;
default = "./data/${name}";
description = "The Open-WebUI data directory";
};

host = lib.mkOption {
type = types.str;
default = "127.0.0.1";
example = "0.0.0.0";
description = ''
The host address which the Open-WebUI server HTTP interface listens to.
'';
};

port = lib.mkOption {
type = types.port;
default = 1111;
example = 11111;
description = ''
Which port the Open-WebUI server listens to.
'';
};

environment = lib.mkOption {
type = types.attrsOf types.str;
default = {
SCARF_NO_ANALYTICS = "True";
DO_NOT_TRACK = "True";
ANONYMIZED_TELEMETRY = "False";
};
example = ''
{
OLLAMA_API_BASE_URL = "http://127.0.0.1:11434";
# Disable authentication
WEBUI_AUTH = "False";
}
'';
description = "Extra environment variables for Open-WebUI";
};

outputs.settings = lib.mkOption {
type = types.deferredModule;
internal = true;
readOnly = true;
default = {
processes = {
"${name}" = {
inherit (config) environment;
command = pkgs.writeShellApplication {
name = "open-webui-wrapper";
runtimeInputs = [ pkgs.open-webui ];
text = ''
set -x
if [ ! -d ${config.dataDir} ]; then
mkdir -p ${config.dataDir}
fi
DATA_DIR=$(readlink -f ${config.dataDir})
STATIC_DIR=$DATA_DIR
HF_HOME=$DATA_DIR
SENTENCE_TRANSFORMERS_HOME=$DATA_DIR
export DATA_DIR STATIC_DIR HF_HOME SENTENCE_TRANSFORMERS_HOME
open-webui serve --host ${config.host} --port ${builtins.toString config.port}
'';
};
readiness_probe = {
http_get = {
host = config.host;
port = config.port;
};
initial_delay_seconds = 2;
period_seconds = 10;
timeout_seconds = 4;
success_threshold = 1;
failure_threshold = 5;
};
};
};
};
};
};
}
21 changes: 21 additions & 0 deletions nix/open-webui_test.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{ pkgs, ... }: {
services.open-webui."open-webui1" = {
enable = true;
environment = {
# Requires network connection
RAG_EMBEDDING_MODEL = "";
};
};

settings.processes.test = {
command = pkgs.writeShellApplication {
runtimeInputs = [ pkgs.curl ];
text = ''
# Avoid printing the entire HTML page on the stdout, we just want to know if the page is active.
curl http://127.0.0.1:1111 > /dev/null
'';
name = "open-webui-test";
};
depends_on."open-webui1".condition = "process_healthy";
};
}
1 change: 1 addition & 0 deletions test/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"${inputs.services-flake}/nix/elasticsearch_test.nix"
"${inputs.services-flake}/nix/mysql/mysql_test.nix"
"${inputs.services-flake}/nix/nginx/nginx_test.nix"
"${inputs.services-flake}/nix/open-webui_test.nix"
"${inputs.services-flake}/nix/postgres/postgres_test.nix"
"${inputs.services-flake}/nix/redis_test.nix"
"${inputs.services-flake}/nix/redis-cluster_test.nix"
Expand Down

0 comments on commit 399b858

Please sign in to comment.