Skip to content

Commit

Permalink
nixos/open-webui: init
Browse files Browse the repository at this point in the history
  • Loading branch information
shivaraj-bh committed Jun 4, 2024
1 parent 1860d78 commit f66cb82
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@
./services/misc/octoprint.nix
./services/misc/ollama.nix
./services/misc/ombi.nix
./services/misc/open-webui.nix
./services/misc/osrm.nix
./services/misc/owncast.nix
./services/misc/packagekit.nix
Expand Down
94 changes: 94 additions & 0 deletions nixos/modules/services/misc/open-webui.nix
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 ];
}
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ in {
outline = handleTest ./outline.nix {};
image-contents = handleTest ./image-contents.nix {};
openvscode-server = handleTest ./openvscode-server.nix {};
open-webui = runTest ./open-webui.nix;
orangefs = handleTest ./orangefs.nix {};
os-prober = handleTestOn ["x86_64-linux"] ./os-prober.nix {};
osquery = handleTestOn ["x86_64-linux"] ./osquery.nix {};
Expand Down
33 changes: 33 additions & 0 deletions nixos/tests/open-webui.nix
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}")
'';
}

0 comments on commit f66cb82

Please sign in to comment.