Use Environments#
This guide provides practical recipes for the environment backends supported
by oxo-flow. The engine ships eight backends: conda, mamba, pixi,
docker, singularity, venv, modules (HPC environment modules), and
system (the implicit fallback when a rule declares no environment).
Recipes below cover the most commonly used ones; mamba uses the same YAML
syntax as conda, and modules takes a list of HPC module names.
Conda Environments#
Create an environment file#
# envs/alignment.yaml
name: alignment
channels:
- bioconda
- conda-forge
dependencies:
- bwa=0.7.19
- samtools=1.24
- picard=3.1.1
Reference it in a rule#
[[rules]]
name = "align"
environment = { conda = "envs/alignment.yaml" }
shell = "bwa mem ref.fa reads.fastq.gz | samtools sort -o aligned.bam"
How it works#
- oxo-flow checks if the environment already exists (keyed by the YAML specification)
- If not, it creates it from the YAML file
- The shell command runs inside the environment via
conda run --no-capture-output -n <env-name> bash -c 'export PATH="$CONDA_PREFIX/bin:$PATH"; <command>', where<env-name>is thename:from your YAML plus a short content-hash suffix for file specs (<name>-<hash8>, see workflow-format) — so two different YAMLs that happen to share a name never collide - The environment is created once and reused by every rule that references the same YAML
Reuse environments
Multiple rules can share the same conda YAML file. oxo-flow creates the environment once and reuses it — identical YAML content reuses the same env even across workflows.
Docker Containers#
Use a BioContainers image#
[[rules]]
name = "align"
environment = { docker = "quay.io/biocontainers/bwa:0.7.19--h577a1d6_1" }
shell = "bwa mem ref.fa reads.fastq.gz | samtools sort -o aligned.bam"
Use a custom image#
Volume mounting#
oxo-flow automatically mounts the working directory into the container. Input and output paths are resolved relative to the mount point.
Pull policy#
Images are pulled on first use. If you need offline operation, pre-pull images:
Bare image names get one automatic retry against quay.io after a Docker Hub miss — Biocontainers publishes on quay.io, not Docker Hub:
biocontainers/bwa:0.7.17→ retried asquay.io/biocontainers/bwa:0.7.17bwa:0.7.17(single name) → retried asquay.io/biocontainers/bwa:0.7.17
Explicit registries (quay.io/…, docker.io/…, localhost:5000/…) are
pulled verbatim and never shadowed by the retry.
Singularity / Apptainer#
Pull from Docker Hub#
[[rules]]
name = "align"
environment = { singularity = "docker://quay.io/biocontainers/bwa:0.7.19--h577a1d6_1" }
shell = "bwa mem ref.fa reads.fastq.gz > aligned.sam"
Use a local SIF file#
HPC considerations#
Singularity is the preferred container runtime for HPC clusters because it:
- Does not require root privileges
- Integrates with cluster schedulers (SLURM, PBS)
- Supports shared filesystem mounts automatically
Pixi Environments#
Create a pixi.toml#
# pixi.toml — at the workflow root (the directory you run oxo-flow from)
[project]
name = "qc-tools"
channels = ["bioconda", "conda-forge"]
platforms = ["linux-64"]
[dependencies]
fastqc = "0.12.1"
fastp = "0.23.4"
Reference in a rule#
The pixi value is the path to the manifest file (pixi.toml),
relative to the workflow root:
[[rules]]
name = "fastqc"
environment = { pixi = "pixi.toml" }
shell = "fastqc input.fastq.gz -o qc/"
oxo-flow runs pixi install --manifest-path pixi.toml once, then wraps the
command as pixi run --manifest-path pixi.toml bash -c '<command>' — the
bash -c wrapper keeps shell operators and multi-line scripts inside the
pixi environment (pixi run is a child-process env, not a PATH mutation).
Python Virtual Environments#
Create a requirements file#
Reference in a rule#
The venv value is the directory where the virtual environment is
created; the requirements file goes in the separate venv_requirements
field (defaults to requirements.txt in the working directory):
[[rules]]
name = "plot_results"
environment = { venv = "venv/", venv_requirements = "envs/requirements.txt" }
shell = "python scripts/plot.py --input results.csv --output plot.png"
How it works#
- oxo-flow creates the venv at the given directory with
python3 -m venv(or reuses it if it already exists) - Packages from the requirements file are installed with pip
- The shell command runs with the venv activated (
source <dir>/bin/activate && <command>)
Environments on Cluster Backends#
Local runs always execute the environment wrapper on the machine running
oxo-flow (docker run, singularity exec, conda run, …). On the
Kubernetes cluster backend a container environment is instead rendered as
the pod's own image, so the pod needs no container runtime:
| Declared environment | Kubernetes rendering | Local run (unchanged) |
|---|---|---|
docker = "<image>" |
Image mode — pod image: = <image>, no wrapper |
docker run wrapper |
singularity = "docker://<image>" |
Image mode — pod image: = the underlying <image> |
singularity exec on the pulled SIF |
singularity = "/path/x.sif" or another URI scheme |
Wrapper fallback — folded singularity exec runs in the pod (cannot get a runtime-bearing base image: adding docker wins kind() → image mode) |
singularity exec |
conda / mamba / pixi |
Wrapper fallback — folded runtime wrapper runs in the pod; declare docker = "<image with the runtime>" too (these rank above docker) |
native wrapper |
venv |
Wrapper fallback — activation runs in the pod (adding docker wins kind() → image mode; bake or run locally) |
native wrapper |
modules |
Wrapper fallback — module load runs in the pod shell (modules + docker is rejected) |
native module load |
| no environment | system — no wrapper exists; the command runs in ubuntu:latest (the historical pod base image) |
host shell |
Image mode applies OXO_REGISTRY_MIRRORS when the manifest's image: field is
rendered; the environment identity (cache key, run provenance) keeps the
workflow-declared spec, so a mirrored box and a direct box agree. It also keeps
the local container wrapper's shell contract: the pod starts /bin/sh and runs
the rule text (and each Indexed-Job command file) with bash when the image has
it, else with sh, so a bash-less image still starts and a bash-bearing image
keeps set -euo pipefail/[[ ]] semantics.
Fallbacks are visible in the Job manifest (oxoflow.io/environment-render:
wrapper-fallback; a system rule is system) and in one warning per rendered
Job. OXO_FLOW_K8S_IMAGE_RENDER=0 forces the fallback box-wide (the warning
then says rendering is disabled, not impossible). The fallback pod's base image
is ubuntu:latest unless the rule also declares docker: mamba/conda/pixi
rank above docker, so those can pair a runtime-bearing base image with their
wrapper and run; a local SIF and venv rank below docker (adding an image
flips to image mode), and modules + docker is rejected — those three are
rendered and warned about but cannot execute on Kubernetes today: bake an image
and declare docker = …, or run them on a local/HPC backend. The fallback is
also functional for a docker rule that opts out (pair it with
OXO_FLOW_K8S_DOCKER_SOCKET=1) and for a system rule that invokes docker
itself.
The full matrix, provenance record, and limits are documented in Run on a Cluster → Container environments on Kubernetes.
Mixing Backends in One Workflow#
[[rules]]
name = "align"
environment = { docker = "biocontainers/bwa:0.7.19--h577a1d6_1" }
# ...
[[rules]]
name = "call_variants"
environment = { conda = "envs/gatk.yaml" }
# ...
[[rules]]
name = "annotate"
environment = { singularity = "docker://ensemblorg/ensembl-vep:112.0" }
# ...
[[rules]]
name = "report"
environment = { venv = "venv/", venv_requirements = "envs/requirements.txt" }
# ...
Mamba and HPC Modules#
The mamba backend uses the exact same YAML format as conda with a faster
solver (and falls back to conda when only conda is installed); the modules
backend loads HPC environment modules (Lmod/Environment Modules) before the
rule's shell command. Both have dedicated walkthroughs in the
Environment Management tutorial
— see its HPC Modules
section for modules = ["gcc/11.2.0", …] recipes.
Checking Availability#
# List all backends available on this system
oxo-flow env list
# Check all environments in a specific workflow
oxo-flow env check pipeline.oxoflow
Troubleshooting#
| Problem | Solution |
|---|---|
conda: command not found |
Install Miniconda/Miniforge and ensure conda is on your $PATH |
| Docker permission denied | Add your user to the docker group or use Singularity |
| Singularity pull fails | Check network access; pre-pull images with singularity pull |
| Pip install fails in venv | Ensure python3 and pip are available on the system |
See Also#
- Environment Management tutorial — getting started with environments
- Environment System reference — architecture details