incineroar: refactor nix-shell into new playground for generative software
This commit is contained in:
parent
6321af89af
commit
ebc3fda1d3
@ -82,6 +82,7 @@ in
|
|||||||
isNormalUser = true;
|
isNormalUser = true;
|
||||||
extraGroups = [ "wheel" ];
|
extraGroups = [ "wheel" ];
|
||||||
packages = with pkgs; [
|
packages = with pkgs; [
|
||||||
|
gnumake
|
||||||
chromium
|
chromium
|
||||||
firefox
|
firefox
|
||||||
ffmpeg
|
ffmpeg
|
||||||
@ -288,26 +289,16 @@ in
|
|||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
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
|
${host_fqdn}:4430 { # node_exporter
|
||||||
${tlsConfig}
|
${tlsConfig}
|
||||||
reverse_proxy http://127.0.0.1:8030
|
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
|
${host_fqdn}:4431 { # litellm
|
||||||
${tlsConfig}
|
${tlsConfig}
|
||||||
reverse_proxy http://127.0.0.1:8031
|
reverse_proxy http://127.0.0.1:8031
|
||||||
@ -316,6 +307,22 @@ in
|
|||||||
${tlsConfig}
|
${tlsConfig}
|
||||||
reverse_proxy http://127.0.0.1:11434
|
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
|
${host_fqdn}:4440 { # sunshine
|
||||||
${tlsConfig}
|
${tlsConfig}
|
||||||
reverse_proxy http://127.0.0.1:47990
|
reverse_proxy http://127.0.0.1:47990
|
||||||
@ -344,13 +351,13 @@ in
|
|||||||
systemd = {
|
systemd = {
|
||||||
services = {
|
services = {
|
||||||
|
|
||||||
comfyui = {
|
playground = {
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "forking";
|
Type = "forking";
|
||||||
User = "blee";
|
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";
|
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";
|
script = "${pkgs.nix}/bin/nix-shell";
|
||||||
|
@ -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
|
|
40
incineroar.brenise.dev/opt/playground/Makefile
Normal file
40
incineroar.brenise.dev/opt/playground/Makefile
Normal file
@ -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."
|
48
incineroar.brenise.dev/opt/playground/README.md
Normal file
48
incineroar.brenise.dev/opt/playground/README.md
Normal file
@ -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/
|
||||||
|
```
|
82
incineroar.brenise.dev/opt/playground/run-playground.sh
Executable file
82
incineroar.brenise.dev/opt/playground/run-playground.sh
Executable file
@ -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
|
@ -1,10 +1,10 @@
|
|||||||
{ pkgs ? import <nixpkgs> {} }:
|
{ pkgs ? import <nixpkgs> {} }:
|
||||||
(pkgs.buildFHSEnv {
|
(pkgs.buildFHSEnv {
|
||||||
name = "comfyui-fhs-env";
|
name = "playground-fhs-env";
|
||||||
targetPkgs = pkgs: with pkgs; [
|
targetPkgs = pkgs: with pkgs; [
|
||||||
tmux
|
tmux
|
||||||
# bash
|
fish
|
||||||
# python311
|
git # for ComfyUI-Manager
|
||||||
];
|
];
|
||||||
runScript = "./run-comfyui.sh";
|
runScript = "./run-playground.sh";
|
||||||
}).env
|
}).env
|
Loading…
x
Reference in New Issue
Block a user