Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

utensils/fooocus-nix

Repository files navigation

fooocus-nix

A Nix flake for Fooocus - an image generating software focused on simplicity.

Features

  • Cross-platform: Linux (x86_64, aarch64) and macOS (Intel, Apple Silicon)
  • Reproducible builds with Nix
  • Automatic GPU detection (NVIDIA CUDA, Apple Silicon MPS, CPU fallback)
  • Persistent data storage in ~/.config/fooocus
  • Docker images (CPU and CUDA variants)
  • Multiple preset support (default, anime, realistic)

Quick Start

Run Fooocus directly without installation:

nix run github:utensils/fooocus-nix

Or with a specific preset:

nix run github:utensils/fooocus-nix#anime
nix run github:utensils/fooocus-nix#realistic

Installation

Using Flakes

Add to your flake.nix:

{
  inputs.fooocus-nix.url = "github:utensils/fooocus-nix";
}

Then use the overlay or package:

# Using the overlay
nixpkgs.overlays = [ fooocus-nix.overlays.default ];

# Or directly reference the package
environment.systemPackages = [ fooocus-nix.packages.${system}.default ];

Local Development

git clone https://github.com/utensils/fooocus-nix
cd fooocus-nix
nix develop  # Enter development shell
nix run      # Run Fooocus

Usage

Command Line Options

# Run with default settings
nix run .

# Open browser automatically when ready
nix run . -- --open

# Use a specific port
nix run . -- --port=7866

# Listen on all interfaces (for network access)
nix run . -- --listen 0.0.0.0

# Use a preset
nix run . -- --preset=anime

# Enable debug logging
nix run . -- --debug

Available Apps

Command Description
nix run Run Fooocus with default preset
nix run .#anime Run with anime preset
nix run .#realistic Run with realistic preset
nix run .#buildDocker Build CPU Docker image
nix run .#buildDockerCuda Build CUDA Docker image
nix run .#update Check for Fooocus updates

Docker

Build and run the Docker image:

# CPU version
nix run .#buildDocker
docker run -p 7865:7865 -v $PWD/data:/data fooocus:latest

# CUDA version (requires nvidia-container-toolkit)
nix run .#buildDockerCuda
docker run --gpus all -p 7865:7865 -v $PWD/data:/data fooocus:cuda

Directory Structure

Fooocus stores persistent data in ~/.config/fooocus:

~/.config/fooocus/
├── app/              # Fooocus application code
├── venv/             # Python virtual environment
├── models/           # Downloaded models
│   ├── checkpoints/  # Main model files
│   ├── loras/        # LoRA models
│   ├── embeddings/   # Text embeddings
│   ├── controlnet/   # ControlNet models
│   └── ...
└── outputs/          # Generated images

GPU Support

The flake automatically detects your GPU:

  • NVIDIA: Uses CUDA (cu124 by default, configurable via CUDA_VERSION env var)
  • Apple Silicon: Uses Metal Performance Shaders (MPS) acceleration
  • Intel Mac: Falls back to CPU-only mode
  • CPU: Falls back to CPU-only mode on any platform

NVIDIA (Linux)

Override CUDA version:

CUDA_VERSION=cu121 nix run .

Supported CUDA versions: cu118, cu121, cu124, cpu

Apple Silicon (macOS)

On M1/M2/M3/M4 Macs, PyTorch automatically uses MPS (Metal Performance Shaders) for GPU acceleration. No additional configuration is required.

Note: First run will download macOS-specific PyTorch wheels which may take a few minutes.

Development

Enter Development Shell

nix develop

This provides:

  • Python 3.12 environment
  • Development tools (git, shellcheck, shfmt)
  • Linting tools (ruff, pyright)
  • Nix formatting (nixfmt-rfc-style)

Code Quality

# Run all checks
nix flake check

# Individual checks
nix run .#lint        # Python linting
nix run .#format      # Python formatting
nix run .#type-check  # Type checking
nix run .#check-all   # All Python checks

Updating Fooocus Version

Fooocus is tracked as a flake input, so updating to HEAD is simple:

nix flake update fooocus-src

Troubleshooting

Port Already in Use

If port 7865 is already in use, the launcher will offer options to:

  1. Open browser to existing instance
  2. Use a different port
  3. Kill the process using the port

CUDA Not Detected

If CUDA isn't detected despite having an NVIDIA GPU:

  1. Ensure NVIDIA drivers are installed
  2. Check that nvidia-smi works
  3. Try setting CUDA_VERSION explicitly

First Run is Slow

The first run downloads:

  • Python dependencies
  • PyTorch with appropriate GPU support
  • Base models (automatically on first generation)

Subsequent runs use cached dependencies.

Log Button Shows "File not allowed"

This issue is now handled automatically by the flake. The launcher sets the path_outputs environment variable to bypass Gradio's symlink security restrictions.

If you still encounter {"detail":"File not allowed: .../log.html"}, manually edit ~/.config/fooocus/app/config.txt:

"path_outputs": "/home/YOUR_USER/.config/fooocus/outputs"

Change from .../app/outputs to the real path (without the app/ symlink), then restart Fooocus.

License

This project contains two components with different licenses:

  • Packaging code (Nix expressions, shell scripts): MIT License - see LICENSE
  • Fooocus application: GPL-3.0 - see the Fooocus repository

The Nix package metadata reflects GPL-3.0 as that is the license of the packaged software.

Acknowledgments

About

A Nix flake for Fooocus - image generation focused on simplicity

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors 2

  •  
  •