| name | flox-sharing |
| description | Sharing and composing Flox environments. Use for environment composition, remote environments, FloxHub, and team collaboration patterns. |
Flox Environment Sharing & Composition Guide
Core Concepts
Composition: Build-time merging of environments (deterministic)
Remote Environments: Shared environments via FloxHub
Team Collaboration: Reusable, shareable environment stacks
Understanding Environment Sharing
The .flox/ directory contains the environment definition:
- Package specifications and versions
- Environment variables
- Build definitions
- Hooks and services configuration
The environment definition does NOT include:
- Built binaries/artifacts (those are created by builds and can be published as packages)
- Local data or cache
Two sharing mechanisms:
- Git: Commit
.flox/ directory to git. When used with development environments, this is typically alongside your source code in the same repository. Other developers clone the repo and get both the environment definition and source code.
- FloxHub: Push environment definition only using
flox push. This shares ONLY the .flox/ directory, not any source code or other files. Useful for runtime environments or shared base environments used across multiple projects.
This is different from publishing packages (see flox-publish skill), where you build and distribute the actual binaries/artifacts.
Core Commands
flox activate -r owner/environment-name
flox pull owner/environment-name
flox push
Environment Composition
Basic Composition
Merge environments at build time using [include]:
[include]
environments = [
{ remote = "team/postgres" },
{ remote = "team/redis" },
{ remote = "team/python-base" }
]
Creating Composition-Optimized Environments
Design for clean merging at build time:
[install]
gcc.pkg-path = "gcc"
gcc.pkg-group = "compiler"
[vars]
POSTGRES_PORT = "5432"
[hook]
setup_postgres() {
[ -d "$FLOX_ENV_CACHE/postgres" ] || init_db
}
Best practices:
- No overlapping vars, services, or function names
- Use explicit, namespaced naming (e.g.,
postgres_init not init)
- Minimal hook logic (composed envs run ALL hooks)
- Avoid auto-run logic in
[profile] (runs once per layer/composition; help displays will repeat)
- Test composability:
flox activate each env standalone first
Composition Example: Full Stack
[include]
environments = [
{ remote = "team/postgres" },
{ remote = "team/redis" },
{ remote = "team/nodejs" },
{ remote = "team/monitoring" }
]
[vars]
POSTGRES_HOST = "localhost"
POSTGRES_PORT = "5433"
Use Cases for Composition
Reproducible stacks:
[include]
environments = [
{ remote = "team/cuda-base" },
{ remote = "team/cuda-math" },
{ remote = "team/python-ml" }
]
Shared base configuration:
[include]
environments = [
{ remote = "org/standards" },
{ remote = "team/backend" }
]
Creating Dual-Purpose Environments
Design for both layering and composition:
[install]
python.pkg-path = "python311"
python.pkg-group = "runtime"
[vars]
MYPROJECT_VERSION = "1.0"
MYPROJECT_CONFIG = "$FLOX_ENV_CACHE/config"
[profile.common]
if ! type myproject_init >/dev/null 2>&1
myproject_init() { ... }
fi
Remote Environments
Activating Remote Environments
flox activate -r owner/environment-name
flox activate -r owner/environment-name -- npm test
Pulling Remote Environments
flox pull owner/environment-name
flox activate
Pushing Environments to FloxHub
git init
git add .flox/
git commit -m "Initial environment"
flox push
Choosing Between Git and FloxHub
Commit .flox/ to Git when:
- Environment is for development (includes build tools)
- Environment lives alongside source code
- You want version control history for environment changes
- Team already uses git for collaboration
Push to FloxHub when:
- Environment is for runtime/production (no source code needed)
- Creating shared base environments used across multiple projects
- Environment needs to be independently versioned from source code
- You want to share environment without exposing source code
Recommended pattern: Commit development environments to git with source code; push runtime environments to FloxHub.
Team Collaboration Patterns
Base + Specialization
Create base environment:
[install]
git.pkg-path = "git"
gh.pkg-path = "gh"
jq.pkg-path = "jq"
[vars]
ORG_REGISTRY = "registry.company.com"
Specialize for teams:
[include]
environments = [{ remote = "team/base" }]
[install]
nodejs.pkg-path = "nodejs"
pnpm.pkg-path = "pnpm"
[include]
environments = [{ remote = "team/base" }]
[install]
python.pkg-path = "python311Full"
uv.pkg-path = "uv"
Service Libraries
Create reusable service environments:
[install]
postgresql.pkg-path = "postgresql"
[services.postgres]
command = '''
mkdir -p "$FLOX_ENV_CACHE/postgres"
if [ ! -d "$FLOX_ENV_CACHE/postgres/data" ]; then
initdb -D "$FLOX_ENV_CACHE/postgres/data"
fi
exec postgres -D "$FLOX_ENV_CACHE/postgres/data" \
-h "$POSTGRES_HOST" -p "$POSTGRES_PORT"
'''
is-daemon = true
[vars]
POSTGRES_HOST = "localhost"
POSTGRES_PORT = "5432"
Compose into projects:
[include]
environments = [
{ remote = "team/postgres-service" },
{ remote = "team/redis-service" }
]
Development vs Runtime Environments
Development environment (for building):
[install]
gcc.pkg-path = "gcc13"
make.pkg-path = "make"
debugpy.pkg-path = "python311Packages.debugpy"
pytest.pkg-path = "python311Packages.pytest"
[build.myapp]
command = '''
make release
mkdir -p $out/bin
cp build/myapp $out/bin/
'''
version = "1.0.0"
[vars]
DEBUG = "true"
LOG_LEVEL = "debug"
Developers commit this .flox/ directory to git with the source code. Other developers git clone and flox activate to get the same development environment.
Runtime environment (for consuming):
[install]
myapp.pkg-path = "myorg/myapp"
[vars]
DEBUG = "false"
LOG_LEVEL = "info"
MYAPP_CONFIG = "$FLOX_ENV_CACHE/config"
After publishing myapp, consumers create this runtime environment and install the published package. The runtime environment can be pushed to FloxHub and shared without exposing source code.
Key distinction: Development environments contain build tools and source code; runtime environments contain published packages (binaries/artifacts).
(See flox-environments skill for layering environments at runtime)
Composition with Local Packages
Combine composed environments with local packages:
[include]
environments = [
{ remote = "team/database-services" },
{ remote = "team/cache-services" }
]
[install]
myapp.pkg-path = "company/myapp"
See flox-environments skill for layering environments at runtime.
Best Practices
For Shareable Environments
- Use descriptive names:
team/postgres-service not db
- Document expectations: What vars/ports/services are provided
- Namespace everything: Prefix vars, functions, services
- Keep focused: One responsibility per environment
- Test standalone:
flox activate should work without composition
For Composed Environments
- No name collisions: Check for overlapping vars/services
- Idempotent hooks: Can run multiple times safely
- Minimal auto-run: Avoid output in
[profile]
- Clear dependencies: Document what environments are needed
(For layering best practices, see flox-environments skill)
Version Management
Pin Specific Versions
[include]
environments = [
{ remote = "team/base", version = "v1.2.3" }
]
Use Latest
[include]
environments = [
{ remote = "team/base" }
]
Troubleshooting
Conflicts in Composition
If composed environments conflict:
- Use different
pkg-group values
- Adjust
priority for file conflicts
- Namespace variables to avoid collisions
- Test each environment standalone first
(For layering troubleshooting, see flox-environments skill)
Remote Environment Not Found
flox search --remote owner/
flox pull owner/environment-name
flox list -c
Related Skills
- flox-environments - Creating base environments
- flox-services - Sharing service configurations
- flox-containers - Deploying shared environments
- flox-publish - Publishing built packages (binaries/artifacts) vs sharing environments (definitions only)