diff --git a/incineroar.brenise.dev/configuration.nix b/incineroar.brenise.dev/configuration.nix index 74ec1c2..eeacdfa 100644 --- a/incineroar.brenise.dev/configuration.nix +++ b/incineroar.brenise.dev/configuration.nix @@ -82,6 +82,7 @@ in isNormalUser = true; extraGroups = [ "wheel" ]; packages = with pkgs; [ + gnumake chromium firefox ffmpeg @@ -288,26 +289,16 @@ in } ''; in '' - ${host_fqdn} { # ComfyUI - ${tlsConfig} - reverse_proxy http://127.0.0.1:8080 - - handle /output/* { - root /opt/comfyui - file_server browse - } - - handle /meeseeks/* { - root /mnt/meow/squirtle/var/ftp - file_server browse - } - - } ${host_fqdn}:4430 { # node_exporter ${tlsConfig} reverse_proxy http://127.0.0.1:8030 } + ${host_fqdn} { # open-webui + ${tlsConfig} + reverse_proxy http://127.0.0.1:8080 + + } ${host_fqdn}:4431 { # litellm ${tlsConfig} reverse_proxy http://127.0.0.1:8031 @@ -316,6 +307,22 @@ in ${tlsConfig} reverse_proxy http://127.0.0.1:11434 } + + ${host_fqdn}:4432 { # comfyui + ${tlsConfig} + reverse_proxy http://127.0.0.1:8081 + + handle /output/* { + root /opt/comfyui + file_server browse + } + handle /meeseeks/* { + root /mnt/meow/squirtle/var/ftp + file_server browse + } + + } + ${host_fqdn}:4440 { # sunshine ${tlsConfig} reverse_proxy http://127.0.0.1:47990 @@ -344,13 +351,13 @@ in systemd = { services = { - comfyui = { + playground = { wantedBy = [ "multi-user.target" ]; after = [ "network.target" ]; serviceConfig = { Type = "forking"; User = "blee"; - WorkingDirectory = "/opt/comfyui"; + WorkingDirectory = "/opt/playground"; Environment = "NIX_PATH=nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels"; }; script = "${pkgs.nix}/bin/nix-shell"; diff --git a/incineroar.brenise.dev/opt/comfyui/run-comfyui.sh b/incineroar.brenise.dev/opt/comfyui/run-comfyui.sh deleted file mode 100755 index 03efc7f..0000000 --- a/incineroar.brenise.dev/opt/comfyui/run-comfyui.sh +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env bash - -# ComfyUI Tmux Launcher -# -# This script starts ComfyUI in a detached tmux session. It allows for easy -# configuration of session name, port, listen address, and low VRAM mode. -# -# Usage: -# ./script.sh [SESSION_NAME] [PORT] [LISTEN_ADDRESS] [LOWVRAM] -# -# Arguments: -# SESSION_NAME : Name of the tmux session (default: imagegen) -# PORT : Port number for ComfyUI to listen on (default: 8080) -# LISTEN_ADDRESS : IP address to bind to (default: 127.0.0.1) -# LOWVRAM : Enable low VRAM mode (default: false) -# -# Examples: -# 1. Run with default settings: -# ./script.sh -# -# 2. Custom session name: -# ./script.sh mycustomsession -# -# 3. Custom session, port, and address: -# ./script.sh mycustomsession 8090 0.0.0.0 -# -# 4. Enable low VRAM mode: -# ./script.sh imagegen 8080 127.0.0.1 true -# -# Note: This script requires tmux to be installed and a virtual environment -# to be set up in the .venv directory. - -# Exit on error, undefined variables, and print commands -#set -eux -set -e - -# Default values (can be overridden by command-line arguments) -SESSION_NAME="${1:-imagegen}" -PORT="${2:-8080}" -LISTEN_ADDRESS="${3:-127.0.0.1}" -LOWVRAM="${4:-false}" - -if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then - echo "Session '$SESSION_NAME' already exists. No action taken." - exit 0 -fi - -# Activate virtual environment -source .venv/bin/activate - -# Check if session already exists -if ! tmux has-session -t "$SESSION_NAME" 2>/dev/null; then - # Create new detached session - tmux new-session -d -s "$SESSION_NAME" - - # Prepare the command - BASE_COMMAND="python main.py --port $PORT --listen $LISTEN_ADDRESS" - if [ "$LOWVRAM" = "true" ]; then - FULL_COMMAND="$BASE_COMMAND --lowvram --preview-method auto --use-split-cross-attention" - else - FULL_COMMAND="$BASE_COMMAND" - fi - - # Start the ComfyUI application - tmux send-keys -t "$SESSION_NAME" "$FULL_COMMAND" C-m - - echo "Session '$SESSION_NAME' created and ComfyUI started." - echo "To connect, type: tmux attach -t $SESSION_NAME" -else - echo "Session '$SESSION_NAME' already exists. Exiting." - exit 1 -fi diff --git a/incineroar.brenise.dev/opt/playground/Makefile b/incineroar.brenise.dev/opt/playground/Makefile new file mode 100644 index 0000000..27593fb --- /dev/null +++ b/incineroar.brenise.dev/opt/playground/Makefile @@ -0,0 +1,40 @@ +# Makefile for managing virtual environments + +VENV_OPEN_WEBUI=.venv_open_webui +VENV_LITELLM=.venv_litellm +ACTIVATE_OPEN_WEBUI=$(VENV_OPEN_WEBUI)/bin/activate +ACTIVATE_LITELLM=$(VENV_LITELLM)/bin/activate + +.PHONY: install install_open_webui install_litellm update update_open_webui update_litellm + +install_open_webui: + @echo "Creating open-webui environment..." + python -m venv $(VENV_OPEN_WEBUI) + . $(ACTIVATE_OPEN_WEBUI) && \ + pip install -U pip open-webui && \ + deactivate + +install_litellm: + @echo "Creating litellm environment..." + python -m venv $(VENV_LITELLM) + . $(ACTIVATE_LITELLM) && \ + pip install -U pip litellm[proxy] && \ + deactivate + +install: install_open_webui install_litellm + @echo "All environments created and packages installed." + +update_open_webui: + @echo "Updating open-webui environment..." + source $(ACTIVATE_OPEN_WEBUI) && \ + pip install -U open-webui && \ + deactivate + +update_litellm: + @echo "Updating litellm environment..." + source $(ACTIVATE_LITELLM) && \ + pip install -U litellm[proxy] && \ + deactivate + +update: update_open_webui update_litellm + @echo "All environments updated." diff --git a/incineroar.brenise.dev/opt/playground/README.md b/incineroar.brenise.dev/opt/playground/README.md new file mode 100644 index 0000000..3123cbf --- /dev/null +++ b/incineroar.brenise.dev/opt/playground/README.md @@ -0,0 +1,48 @@ +# Generative Playground + +This Nix environment starts a tmux session with: + +- ComfyUI +- Ollama +- Open-webui + +It uses a shell script to launch these services on NixOS. + +## Installation + +```sh +mkdir -p /opt/playground +cp -v opt/playground/{Makefile,run-playground.sh, shell.nix} /opt/playground/ +cd /opt/playground +make install +``` + +## Configuration + +Sample `.env` file: + +```sh +export LITELLM_MASTER_KEY= ... +export ANTHROPIC_API_KEY=... +export GOOGLE_API_KEY=... +``` + +## Update + +```sh +cd /opt/playground +make update +``` + +## Running + +```sh +cd /opt/playground +nix-shell +``` + +## Copypasta + +```sh +rsync -tv opt/playground/{run-playground.sh,shell.nix,Makefile} roar:/opt/playground/ +``` diff --git a/incineroar.brenise.dev/opt/playground/run-playground.sh b/incineroar.brenise.dev/opt/playground/run-playground.sh new file mode 100755 index 0000000..f26e6f7 --- /dev/null +++ b/incineroar.brenise.dev/opt/playground/run-playground.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash + +# ComfyUI Tmux Launcher +# +# This script starts ComfyUI in a detached tmux session. It allows for easy +# configuration of session name, port, listen address, and low VRAM mode. +# +# Usage: +# ./script.sh [SESSION_NAME] [PORT] [LISTEN_ADDRESS] [LOWVRAM] +# +# Arguments: +# SESSION_NAME : Name of the tmux session (default: playground) +# PORT : Port number for ComfyUI to listen on (default: 8080) +# LISTEN_ADDRESS : IP address to bind to (default: 127.0.0.1) +# LOWVRAM : Enable low VRAM mode (default: false) +# +# Examples: +# 1. Run with default settings (uses system hostname): +# ./script.sh +# +# 2. Custom session name: +# ./script.sh mycustomsession +# +# 3. Custom session, port, and address: +# ./script.sh mycustomsession 8090 0.0.0.0 +# +# 4. Enable low VRAM mode: +# ./script.sh imagegen 8080 127.0.0.1 true +# +# Note: This script requires tmux to be installed and a virtual environment +# to be set up in the .venv directory. + +# Exit on error, undefined variables, and print commands +set -e + +# Default values (can be overridden by command-line arguments) +# Use "playground" as default session name if not provided +SESSION_NAME="${1:-playground}" +OPEN_WEBUI_PORT="${2:-8080}" +LITELLM_PORT="${3:-8031}" # consistent with litten +COMFYUI_PORT="${4:-8081}" +COMFYUI_LOWVRAM="${5:-false}" + +if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then + echo "Session '$SESSION_NAME' already exists. No action taken." + exit 0 +fi + +# Check if tmux session already exists +if ! tmux has-session -t "$SESSION_NAME" 2>/dev/null; then + + # Create new detached tmux session, starting with open-webui and litellm + tmux new-session -d -s "$SESSION_NAME" -n "textgen" + tmux send-keys -t "$SESSION_NAME":0 "cd /opt/playground && source .venv_open_webui/bin/activate.fish && open-webui serve --port $OPEN_WEBUI_PORT" C-m + tmux split-window -v -t "$SESSION_NAME":0 + tmux send-keys -t "$SESSION_NAME":0.1 "cd /opt/playground && source .venv_litellm/bin/activate.fish && source .env && litellm --telemetry False --config ./litellm.yaml --host 127.0.0.1 --port $LITELLM_PORT" C-m + + # Start ollama in a new window + tmux new-window -t "$SESSION_NAME" -n "ollama" + tmux send-keys -t "$SESSION_NAME":1 "cd /opt/ollama && ./bin/ollama serve" C-m + + # Prepare the ComfyUI launch command + COMFYUI_BASE_COMMAND="python main.py --port $COMFYUI_PORT --listen 127.0.0.1" + if [ "$COMFYUI_LOWVRAM" = "true" ]; then + COMFYUI_LAUNCH_COMMAND="cd /opt/comfyui && source .venv/bin/activate.fish && $COMFYUI_BASE_COMMAND --lowvram --preview-method auto --use-split-cross-attention" + else + COMFYUI_LAUNCH_COMMAND="cd /opt/comfyui && source .venv/bin/activate.fish && $COMFYUI_BASE_COMMAND" + fi + + # Start the ComfyUI application + tmux send-keys -t "$SESSION_NAME" "$COMFYUI_LAUNCH_COMMAND" C-m + + # Start ComfyUI in window 2 + tmux new-window -t "$SESSION_NAME" -n "comfyui" + tmux send-keys -t "$SESSION_NAME":2 "$COMFYUI_LAUNCH_COMMAND" C-m + + echo "Session '$SESSION_NAME' created and ComfyUI, Ollama, and Text Generation services started." + echo "To connect, type: tmux attach -t $SESSION_NAME" +else + echo "Session '$SESSION_NAME' already exists. Exiting." + exit 1 +fi diff --git a/incineroar.brenise.dev/opt/comfyui/shell.nix b/incineroar.brenise.dev/opt/playground/shell.nix similarity index 50% rename from incineroar.brenise.dev/opt/comfyui/shell.nix rename to incineroar.brenise.dev/opt/playground/shell.nix index 4464136..a7567c7 100644 --- a/incineroar.brenise.dev/opt/comfyui/shell.nix +++ b/incineroar.brenise.dev/opt/playground/shell.nix @@ -1,10 +1,10 @@ { pkgs ? import {} }: (pkgs.buildFHSEnv { - name = "comfyui-fhs-env"; + name = "playground-fhs-env"; targetPkgs = pkgs: with pkgs; [ tmux -# bash -# python311 + fish + git # for ComfyUI-Manager ]; - runScript = "./run-comfyui.sh"; + runScript = "./run-playground.sh"; }).env