Flox Environments Guide
Working Style & Structure
- Use modular, idempotent bash functions in hooks
- Never, ever use absolute paths. Flox environments are designed to be reproducible. Use Flox's environment variables instead
- I REPEAT: NEVER, EVER USE ABSOLUTE PATHS. Don't do it. Use for environment-specific runtime dependencies; use for the project directory
- Name functions descriptively (e.g., )
- Consider using gum for styled output when creating environments for interactive use; this is an anti-pattern in CI
- Put persistent data/configs in
- Return to at end of hooks
- Use for temp files, clean up immediately
- Do not over-engineer: e.g., do not create unnecessary echo statements or superfluous comments; do not print unnecessary information displays in or ; do not create helper functions or aliases without the user requesting these explicitly
Configuration & Secrets
- Support
VARIABLE=value flox activate
pattern for runtime overrides
- Never store secrets in manifest; use:
- Environment variables
- for persistent secrets
- Existing config files (e.g., )
Flox Basics
- Flox is built on Nix; fully Nix-compatible
- Flox uses nixpkgs as its upstream; packages are usually named the same; unlike nixpkgs, Flox Catalog has millions of historical package-version combinations
- Key paths:
- : Environment definition
- : Environment metadata
- : Persistent, local-only storage (survives )
- : Project root directory (where .flox/ lives)
- : basically the path to : contains all the libs, includes, bins, configs, etc. available to a specific flox environment
- Always use to create environments
- Manifest changes take effect on next (not live reload)
Core Commands
bash
flox init # Create new env
flox search <string> [--all] # Search for a package
flox show <pkg> # Show available historical versions of a package
flox install <pkg> # Add package
flox list [-e | -c | -n | -a] # List installed packages
flox activate # Enter env
flox activate -- <cmd> # Run without subshell
flox edit # Edit manifest interactively
Manifest Structure
- : Package list with descriptors
- : Static variables
- : Non-interactive setup scripts
- : Shell-specific functions/aliases
- : Service definitions (see flox-services skill)
- : Reproducible build commands (see flox-builds skill)
- : Compose other environments (see flox-sharing skill)
- : Activation mode, supported systems
The [install] Section
Package Installation Basics
The
table specifies packages to install.
toml
[install]
ripgrep.pkg-path = "ripgrep"
pip.pkg-path = "python310Packages.pip"
Package Descriptors
Each entry has:
- Key: Install ID (e.g., , ) - your reference name for the package
- Value: Package descriptor - specifies what to install
Catalog Descriptors (Most Common)
Options for packages from the Flox catalog:
toml
[install]
example.pkg-path = "package-name" # Required: location in catalog
example.pkg-group = "mygroup" # Optional: group packages together
example.version = "1.2.3" # Optional: exact or semver range
example.systems = ["x86_64-linux"] # Optional: limit to specific platforms
example.priority = 3 # Optional: resolve file conflicts (lower = higher priority)
Key Options Explained:
pkg-path (required)
- Location in the package catalog
- Can be simple () or nested ()
- Can use array format:
["python310Packages", "pip"]
pkg-group
- Groups packages that work well together
- Packages without explicit group belong to default group
- Groups upgrade together to maintain compatibility
- Use different groups to avoid version conflicts
version
- Exact:
- Semver ranges: ,
- Partial versions act as wildcards: = latest 1.2.X
systems
- Constrains package to specific platforms
- Options: , , ,
- Defaults to manifest's if omitted
priority
- Resolves file conflicts between packages
- Default: 5
- Lower number = higher priority wins conflicts
- Critical for CUDA packages (see flox-cuda skill)
Practical Examples
toml
# Platform-specific Python
[install]
python.pkg-path = "python311Full"
uv.pkg-path = "uv"
systems = ["x86_64-linux", "aarch64-linux"] # Linux only
# Version-pinned with custom priority
[nodejs]
nodejs.pkg-path = "nodejs"
version = "^20.0"
priority = 1 # Takes precedence in conflicts
# Multiple package groups to avoid conflicts
[install]
gcc.pkg-path = "gcc12"
gcc.pkg-group = "stable"
Language-Specific Patterns
Python Virtual Environments
venv creation pattern: Always check existence before activation:
bash
if [ ! -d "$venv" ]; then
uv venv "$venv" --python python3
fi
# Guard activation - venv creation might not be complete
if [ -f "$venv/bin/activate" ]; then
source "$venv/bin/activate"
fi
Key patterns:
- venv location: Always use - survives environment rebuilds
- uv with venv: Use
uv pip install --python "$venv/bin/python"
NOT
- Cache dirs: Set and to subdirs
- Dependency installation flag: Touch
$FLOX_ENV_CACHE/.deps_installed
to prevent reinstalls
C/C++ Development
- Package Names: not , for Catch2, / for specific versions
- System Constraints: Linux-only tools need explicit systems:
valgrind.systems = ["x86_64-linux", "aarch64-linux"]
- Essential Groups: Separate , , , , groups prevent conflicts
- libstdc++ Access: ALWAYS include for C++ stdlib headers/libs (gcc alone doesn't expose them):
toml
gcc-unwrapped.pkg-path = "gcc-unwrapped"
gcc-unwrapped.priority = 5
gcc-unwrapped.pkg-group = "libraries"
Node.js Development
- Package managers: Install (includes npm); add or separately if needed
- Version pinning: Use for LTS, or exact versions for reproducibility
- Global tools pattern: Use for one-off tools, install commonly-used globals in manifest
Platform-Specific Patterns
toml
# Darwin-specific frameworks
IOKit.pkg-path = "darwin.apple_sdk.frameworks.IOKit"
IOKit.systems = ["x86_64-darwin", "aarch64-darwin"]
# Platform-preferred compilers
gcc.pkg-path = "gcc"
gcc.systems = ["x86_64-linux", "aarch64-linux"]
clang.pkg-path = "clang"
clang.systems = ["x86_64-darwin", "aarch64-darwin"]
# Darwin GNU compatibility layer
coreutils.pkg-path = "coreutils"
coreutils.systems = ["x86_64-darwin", "aarch64-darwin"]
Best Practices
- Check manifest before installing new packages
- Use not in hooks
- Define env vars with
- Use descriptive, prefixed function names in composed envs
- Cache downloads in
- Test activation with
flox activate -- <command>
before adding to services
- Use flag with uv/pip in hooks to reduce noise
Editing Manifests Non-Interactively
bash
flox list -c > /tmp/manifest.toml
# Edit with sed/awk
flox edit -f /tmp/manifest.toml
Common Pitfalls
Hooks Run Every Activation
Hooks run EVERY activation (keep them fast/idempotent)
Hook vs Profile Functions
Hook functions are not available to users in the interactive shell; use
for user-invokable commands/aliases
Profile Code in Layered Environments
Profile code runs for each layered/composed environment; keep auto-run display logic in
to avoid repetition
Manifest Syntax Errors
Manifest syntax errors prevent ALL flox commands from working
Package Search Case Sensitivity
Package search is case-sensitive; use
for broader results
Troubleshooting Tips
Package Conflicts
If packages conflict, use different
values or adjust
Tricky Dependencies
- If we need , we get this from the package, not from
- If user is working with python and requests , they typically do not mean ; clarify which package user wants
Hook Issues
- Use not in hooks
- Define env vars with
- Guard FLOX_ENV_CACHE usage: with fallback
Environment Layering
What is Layering?
Layering is runtime stacking of environments where activate order matters. Each layer runs in its own subshell, preserving isolation while allowing tool composition.
Core Layering Commands
bash
# Layer debugging tools on base environment
flox activate -r team/base -- flox activate -r team/debug
# Layer multiple environments
flox activate -r team/db -- flox activate -r team/cache -- flox activate
# Layer local on remote
flox activate -r prod/app -- flox activate
When to Use Layering
- Ad hoc tool addition: Add debugging/profiling tools temporarily
- Development vs production: Layer dev tools on production environment
- Flexible composition: Mix and match environments at runtime
- Temporary utilities: Add one-time tools without modifying environment
Layering Use Cases
Development tools on production environment:
bash
flox activate -r prod/app -- flox activate -r dev/tools
Debugging tools on CUDA environment:
bash
flox activate -r team/cuda-base -- flox activate -r team/cuda-debug
Temporary utilities:
bash
flox activate -r project/main -- flox activate -r utils/network
Creating Layer-Optimized Environments
Design for runtime stacking with potential conflicts:
toml
[vars]
# Prefix vars to avoid masking
MYAPP_PORT = "8080"
MYAPP_HOST = "localhost"
[profile.common]
# Use unique, prefixed function names
myapp_setup() { ... }
myapp_debug() { ... }
[services.myapp-db] # Prefix service names
command = "..."
Best practices for layerable environments:
- Single responsibility per environment
- Expect vars/binaries might be overridden by upper layers
- Document what the environment provides/expects
- Keep hooks fast and idempotent
- Use prefixed names to avoid collisions
Related Skills
- flox-services - Running services and background processes
- flox-builds - Building and packaging applications
- flox-publish - Publishing packages to catalogs
- flox-sharing - Environment composition and layering
- flox-containers - Containerizing environments
- flox-cuda - CUDA/GPU development environments