This repository has been archived by the owner on Jun 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopen-webui.nix
100 lines (95 loc) · 2.64 KB
/
open-webui.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
{ pkgs, lib, config, ... }:
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";
port = lib.mkOption {
type = types.int;
default = 1111;
description = ''
Port for open-webui.
'';
};
host = lib.mkOption {
type = types.str;
default = "localhost";
description = ''
Host for open-webui.
'';
};
dataDir = lib.mkOption {
type = types.str;
default = "./data/open-webui";
description = ''
Data directory for open-webui.
'';
};
ollamaHost = lib.mkOption {
type = types.str;
default = "localhost";
description = ''
Hostname for ollama service.
'';
};
ollamaPort = lib.mkOption {
type = types.int;
default = 11434;
description = ''
Port for ollama service.
'';
};
};
config = lib.mkIf cfg.enable {
settings.processes = {
open-webui = {
command = pkgs.writeShellApplication {
name = "open-webui-wrapper";
runtimeInputs = [ pkgs.open-webui ];
runtimeEnv = {
OLLAMA_API_BASE_URL = "http://${cfg.ollamaHost}:${builtins.toString cfg.ollamaPort}/api";
WEBUI_PORT = "${builtins.toString cfg.port}";
WEBUI_HOST = cfg.host;
};
text = ''
set -x
if [ ! -d ${cfg.dataDir} ]; then
mkdir -p ${cfg.dataDir}
fi
DATA_DIR=$(readlink -f ${cfg.dataDir})
STATIC_DIR=$DATA_DIR/static
if [ ! -d "$STATIC_DIR" ]; then
mkdir -p "$STATIC_DIR"
fi
export DATA_DIR STATIC_DIR
open-webui
'';
};
readiness_probe = {
http_get = {
host = cfg.host;
port = cfg.port;
};
initial_delay_seconds = 2;
period_seconds = 10;
timeout_seconds = 4;
success_threshold = 1;
failure_threshold = 5;
};
};
open-browser = {
command = pkgs.writeShellApplication {
name = "open-browser";
runtimeInputs = if pkgs.stdenv.isLinux then [ pkgs.xdg-utils ] else [ ];
text = ''
${ if pkgs.stdenv.isLinux then "xdg-open http://${cfg.host}:${builtins.toString cfg.port}" else "" }
${ if pkgs.stdenv.isDarwin then "open http://${cfg.host}:${builtins.toString cfg.port}" else "" }
'';
};
depends_on."open-webui".condition = "process_healthy";
};
};
};
}