Environment Variables
HD Homey is configured using environment variables. This guide covers all available configuration options and how to use them.
Setting Environment Variables
Docker Compose
The recommended approach is to use a .env file:
# Create .env file from example
cp .env-example .env
# Edit .env file
nano .envExample .env file:
# Required
AUTH_SECRET=your-secret-key-here
# Optional - Auto-detection and defaults
HD_HOMEY_PROXY_HOST= # Auto-detects from request if blank
HD_HOMEY_DB_PATH=./data/db/hd_homey.db # Full path to database file
HD_HOMEY_TRANSCODE_DIR=./data/transcoding # Defaults to ${HD_HOMEY_DB_PATH}/transcoding
HD_HOMEY_STREAM_TOKEN_EXPIRY=43200 # 12 hours
FFMPEG_PATH=ffmpeg # Auto-detected from PATH
BETTER_AUTH_URL=http://localhost:3000 # Auto-detected if not set
LOG_LEVEL=info
NODE_ENV=productionThen reference in compose.yml:
services:
hd-homey:
environment:
- AUTH_SECRET=${AUTH_SECRET}
- HD_HOMEY_PROXY_HOST=${HD_HOMEY_PROXY_HOST:-}
# ... other configDocker Run
Pass variables directly with -e flags:
docker run -d \
-e AUTH_SECRET=your-secret-key \
-e HD_HOMEY_PROXY_HOST=https://tuner.example.com \
-e LOG_LEVEL=debug \
ghcr.io/shaunburdick/hd-homey:latestFrom Source
Create a .env file in the project root:
cp .env-example .env
nano .envThe .env file is automatically loaded by Next.js during development and production builds.
Required Variables
AUTH_SECRET
Purpose: Encryption key for Better-Auth session tokens and cryptographic operations.
Format: String, minimum 32 characters (base64 recommended)
Example:
AUTH_SECRET=xK8fN2mP9vQ7wR5tY3uI6oL1nM4bV0cZGeneration:
# Generate a secure random secret
openssl rand -base64 32Security Notes:
- ⚠️ Never commit this to version control
- ⚠️ Keep this secret secure - anyone with this value can forge session tokens
- ⚠️ Changing this invalidates all existing sessions - users will need to sign in again
- ✅ Use a different value for each environment (dev, staging, production)
Critical Security Requirement
AUTH_SECRET must be set before starting HD Homey. The application will not start without it. Never use the example value in production.
Optional Variables
HD_HOMEY_PROXY_HOST
Purpose: External URL for HD Homey, used to generate stream URLs.
Format: Full URL including protocol (http:// or https://)
Default: Auto-detected from incoming request headers (Host, X-Forwarded-Host, etc.)
Required: No - leave blank for auto-detection
Example:
# Auto-detect (recommended for most setups)
HD_HOMEY_PROXY_HOST=
# Explicit URL (for complex proxy configurations)
HD_HOMEY_PROXY_HOST=https://tuner.example.comWhen to set explicitly:
- Running behind a reverse proxy with complex routing
- Auto-detection returns incorrect URLs (e.g., internal IPs instead of external domain)
- Need consistent URLs regardless of how users access HD Homey
When to leave blank (auto-detect):
- Local network access only
- Simple reverse proxy setups where headers are forwarded correctly
- Single access point (one domain/IP)
Auto-Detection Behavior
HD Homey automatically detects your external URL from:
X-Forwarded-Hostheader (ifAUTH_TRUST_HOST=true)Hostheader from the request- Request protocol (http/https)
This works for most configurations including simple reverse proxies. Only set HD_HOMEY_PROXY_HOST if you experience issues with stream URLs.
Reverse Proxy Setup
When using a reverse proxy:
- Leave
HD_HOMEY_PROXY_HOSTblank to use auto-detection - Set
AUTH_TRUST_HOST=trueto trust proxy headers - Configure proxy to forward
HostandX-Forwarded-Hostheaders - Ensure WebSocket support for future features
- Use HTTPS with valid SSL certificates for security
HD_HOMEY_DB_PATH
Purpose: Full path to the SQLite database file.
Format: Filesystem path to database file (relative or absolute)
Default: ./data/db/hd_homey.db
Example:
# Relative path (default)
HD_HOMEY_DB_PATH=./data/db/hd_homey.db
# Absolute path
HD_HOMEY_DB_PATH=/app/data/db/hd_homey.db
# Custom location
HD_HOMEY_DB_PATH=/var/lib/hd-homey/database.dbDatabase directory: The parent directory will be created automatically if it doesn't exist.
Important:
- Must specify the full path including filename (not just directory)
- Parent directory must be writable by the application
- Database file will be created on first run
- Should be backed up regularly
- Use Docker volumes for persistence in containers
Path Change in v1.0.0-beta.3+
Prior versions used HD_HOMEY_DB_PATH as a directory path. Starting in v1.0.0-beta.3, this variable must include the full database filename (e.g., /path/to/hd_homey.db).
HD_HOMEY_TRANSCODE_DIR
Purpose: Directory for temporary transcoding output (HLS segments).
Format: Filesystem path (relative or absolute)
Default: ${HD_HOMEY_DB_PATH}/transcoding (parent directory of database + /transcoding)
Required: No - uses default if not specified
Example:
# Custom location
HD_HOMEY_TRANSCODE_DIR=/tmp/transcoding
# Will default to:
# If HD_HOMEY_DB_PATH=./data/db/hd_homey.db
# Then HD_HOMEY_TRANSCODE_DIR=./data/db/transcodingAutomatic Cleanup:
- Segments are automatically deleted when transcoding session ends
- No manual cleanup required
- Directory is created automatically if it doesn't exist
Performance Optimization: For best performance, use a RAM-based filesystem (tmpfs):
# compose.yml
volumes:
- transcode-tmp:/tmp/transcoding
volumes:
transcode-tmp:
driver: local
driver_opts:
type: tmpfs
device: tmpfs
o: size=1g,uid=1001,gid=1001# Then set in .env
HD_HOMEY_TRANSCODE_DIR=/tmp/transcodingBenefits of tmpfs:
- ✅ Faster read/write (in RAM)
- ✅ Automatic cleanup on restart
- ✅ Reduces disk I/O
- ⚠️ Requires adequate RAM (allocate ~100MB per concurrent 1080p stream)
HD_HOMEY_STREAM_TOKEN_EXPIRY
Purpose: Validity duration for stream authentication tokens.
Format: Integer (seconds)
Default: 43200 (12 hours)
Example:
# 24 hours
HD_HOMEY_STREAM_TOKEN_EXPIRY=86400
# 1 hour
HD_HOMEY_STREAM_TOKEN_EXPIRY=3600
# 7 days
HD_HOMEY_STREAM_TOKEN_EXPIRY=604800Considerations:
- Shorter duration: More secure, but users need to refresh URLs more frequently
- Longer duration: More convenient, but increases risk if URLs are leaked
- Recommended: 12-24 hours for most use cases
Token regeneration: Users can generate new tokens anytime by visiting the channel details page.
FFMPEG_PATH
Purpose: Path to the FFmpeg binary executable.
Format: Filesystem path to executable
Default: ffmpeg (auto-detected from system PATH)
Required: No - FFmpeg is automatically detected if available in PATH
Example:
# Auto-detect (default - leave unset)
# FFMPEG_PATH=
# Explicit path if needed
FFMPEG_PATH=/usr/local/bin/ffmpeg
# Specific version
FFMPEG_PATH=/opt/ffmpeg-6.1/bin/ffmpegAuto-Detection: HD Homey automatically searches for FFmpeg in:
- System PATH environment variable
- Common installation locations (
/usr/bin/ffmpeg,/usr/local/bin/ffmpeg) - Docker images include FFmpeg pre-installed
When to set explicitly:
- FFmpeg installed in non-standard location
- Multiple FFmpeg versions installed (need specific one)
- Auto-detection fails
Requirements:
- FFmpeg version 4.0+ (5.0+ recommended)
- Compiled with H.264 (libx264) and AAC codecs
- Docker images include FFmpeg automatically
Verification:
# Check if FFmpeg is detected
# Docker
docker exec hd-homey ffmpeg -version
# Source install
ffmpeg -versionInstalling FFmpeg
Ubuntu/Debian:
sudo apt update && sudo apt install ffmpegmacOS:
brew install ffmpegFrom source: See FFmpeg Compilation Guide
Docker users: FFmpeg is pre-installed in HD Homey Docker images - no action needed.
BETTER_AUTH_URL
Purpose: Base URL for Better-Auth endpoints and authentication redirects.
Format: Full URL including protocol
Default: Auto-detected from request headers or falls back to NEXTAUTH_URL
Required: No - auto-detection works for most configurations
Example:
# Auto-detect (recommended - leave blank)
# BETTER_AUTH_URL=
# Explicit URL if auto-detection fails
BETTER_AUTH_URL=https://tuner.example.comAuto-Detection Order:
BETTER_AUTH_URLenvironment variable (if set)NEXTAUTH_URLenvironment variable (if set)- Auto-detect from request headers (Host, X-Forwarded-Host)
- Fallback to
http://localhost:3000
When to set explicitly:
- Running behind a reverse proxy with complex routing
- Better-Auth authentication redirects fail
- Need explicit control over authentication URLs
- Multiple domains pointing to same instance
When to leave blank (auto-detect):
- Simple reverse proxy configurations
- Single access point (one domain)
HD_HOMEY_PROXY_HOSTis sufficient for most cases
Relationship to HD_HOMEY_PROXY_HOST
In most configurations, you don't need to set BETTER_AUTH_URL if HD_HOMEY_PROXY_HOST is configured correctly. Auto-detection will use the same URL as your stream proxy host.
NEXTAUTH_URL
Purpose: Fallback for BETTER_AUTH_URL (legacy compatibility).
Format: Full URL including protocol
Default: Auto-detected
Example:
NEXTAUTH_URL=https://tuner.example.comNote: BETTER_AUTH_URL takes precedence if both are set.
NODE_ENV
Purpose: Runtime environment mode.
Format: String (development, production, test)
Default: development
Example:
NODE_ENV=productionEffects:
development: Enables hot reloading, verbose logs, dev toolsproduction: Optimized builds, reduced logging, performance modetest: Test environment configuration
Docker default: Set to production in Docker images.
LOG_LEVEL
Purpose: Logging verbosity level.
Format: String (trace, debug, info, warn, error, fatal)
Default: info
Example:
# More verbose (for debugging)
LOG_LEVEL=debug
# Less verbose (production)
LOG_LEVEL=warnLog Levels:
trace: Extremely verbose (every function call)debug: Detailed debugging informationinfo: General informational messages (default)warn: Warning messages (potential issues)error: Error messages (failures)fatal: Fatal errors (application crashes)
Recommended:
- Development:
debug - Production:
infoorwarn - Troubleshooting:
debugortrace
AUTH_TRUST_HOST
Purpose: Trust the X-Forwarded-Host header from reverse proxies.
Format: Boolean (true, false)
Default: false
Example:
AUTH_TRUST_HOST=trueWhen to enable:
- Running behind a reverse proxy (nginx, Caddy, Traefik)
- Proxy sets
X-Forwarded-Hostheader correctly
Security warning: Only enable if you trust your reverse proxy. Malicious X-Forwarded-Host headers could redirect authentication to attacker-controlled domains.
FFMPEG_THREADS
Purpose: Number of threads FFmpeg uses for transcoding.
Format: Integer (number of CPU threads)
Default: 2
Example:
# Use 4 threads per transcoding session
FFMPEG_THREADS=4
# Use 1 thread (lowest CPU usage)
FFMPEG_THREADS=1Considerations:
- More threads = faster transcoding startup, higher CPU usage
- Fewer threads = slower transcoding startup, lower CPU usage
- Recommended: 2-4 threads for most systems
- Total CPU usage =
FFMPEG_THREADS × concurrent_streams × 15-20%
Configuration Examples
Local Network Only
# .env
AUTH_SECRET=xK8fN2mP9vQ7wR5tY3uI6oL1nM4bV0cZ
# Optional - Use defaults and auto-detection
# HD_HOMEY_PROXY_HOST= # Auto-detect from request
# HD_HOMEY_DB_PATH=./data/db/hd_homey.db # Default location
# BETTER_AUTH_URL= # Auto-detect
LOG_LEVEL=infoRemote Access with Reverse Proxy
# .env
AUTH_SECRET=xK8fN2mP9vQ7wR5tY3uI6oL1nM4bV0cZ
# Explicit external URL (or leave blank to auto-detect)
HD_HOMEY_PROXY_HOST=https://tuner.example.com
# Trust proxy headers for auto-detection
AUTH_TRUST_HOST=true
LOG_LEVEL=info
NODE_ENV=productionDevelopment Setup
# .env
AUTH_SECRET=dev-secret-not-for-production
# Custom paths for development
HD_HOMEY_DB_PATH=./dev-data/db/hd_homey.db
HD_HOMEY_TRANSCODE_DIR=./dev-data/transcoding
LOG_LEVEL=debug
NODE_ENV=developmentHigh-Performance Setup
# .env
AUTH_SECRET=xK8fN2mP9vQ7wR5tY3uI6oL1nM4bV0cZ
# Use tmpfs for transcoding (configure in docker-compose)
HD_HOMEY_TRANSCODE_DIR=/tmp/transcoding
# Increase transcode threads for faster encoding
FFMPEG_THREADS=4
LOG_LEVEL=warn
NODE_ENV=productionEnvironment Variable Priority
When multiple methods set the same variable:
- Docker run
-eflags (highest priority) - Docker Compose
environment:section .envfile referenced by Docker Compose- Container's built-in defaults (lowest priority)
Verification
Check which environment variables are active:
# Docker Compose
docker compose exec hd-homey env | grep HD_HOMEY
# Docker Run
docker exec hd-homey env | grep HD_HOMEYView configuration in the HD Homey UI:
- Navigate to About page
- Configuration summary is displayed (sensitive values hidden)
Troubleshooting
Changes Not Taking Effect
Solution: Restart the application after modifying environment variables.
# Docker Compose
docker compose restart
# Docker Run
docker restart hd-homey
# From source
# Stop dev server (Ctrl+C) and restart
npm run devAUTH_SECRET Not Set Error
Error: "AUTH_SECRET environment variable is required"
Solution:
- Verify
.envfile exists - Check
AUTH_SECRETis set in.env - Ensure Docker Compose references
${AUTH_SECRET} - Restart container
Stream URLs Using Wrong Domain
Problem: Stream URLs contain internal IP instead of external domain
Solution:
- Try auto-detection first: Leave
HD_HOMEY_PROXY_HOSTblank and ensure:AUTH_TRUST_HOST=trueif behind a reverse proxy- Proxy forwards
HostorX-Forwarded-Hostheaders correctly
- If auto-detection fails: Set
HD_HOMEY_PROXY_HOSTexplicitly to your external URL - Restart HD Homey and verify stream URLs
Security Best Practices
Use strong AUTH_SECRET
- Minimum 32 characters
- Random, cryptographically secure
- Different for each environment
Protect .env files
bashchmod 600 .env- Add
.envto.gitignore - Never commit to version control
- Add
Rotate secrets periodically
- Update
AUTH_SECRETevery 90 days - Regenerate stream secrets monthly (via Settings page)
- Update
Use HTTPS for remote access
- Set
HD_HOMEY_PROXY_HOSTwithhttps:// - Configure reverse proxy with valid SSL certificates
- Disable HTTP access from internet
- Set
Minimize exposed variables
- Only set variables you need
- Use defaults when appropriate
- Document custom values for team members
Next Steps
- Database Configuration - Learn about database management and backups
- Installation Guide - Return to installation instructions
- Troubleshooting - Solve common configuration issues
