

# Nextflow workflow definition specifics

HealthOmics supports Nextflow DSL1 and DSL2. For details, see [Nextflow version support](workflows-lang-versions.md#workflows-lang-versions-nextflow).

Nextflow DSL2 is based on the Groovy programming language, so parameters are dynamic and type coercion is possible using the same rules as Groovy. Parameters and values supplied by the input JSON are available in the parameters (`params`) map of the workflow.

For more information about linting a Nextflow definition before you create the workflow, see [Validating workflow definitions locally](workflows-validate-local.md).

**Topics**
+ [Use nf-schema and nf-validation plugins](#schema-and-validation-plugins-nextflow)
+ [Specify storage URIs](#storage-uris-nextflow)
+ [Nextflow directives](#workflow-nexflow-directives)
+ [Use Nextflow profiles](#nextflow-profiles)
+ [Specify Nextflow configuration at runtime](#nextflow-runtime-config)
+ [Export workflow-level content](#exporting-workflow-content-nextflow)
+ [Export task content](#exporting-task-content-nextflow)
+ [Generate Nextflow execution reports](#nextflow-execution-reports)
+ [Specify the Nextflow syntax version](#nextflow-syntax-version)
+ [Automatic syntax validation during workflow creation](#nextflow-automatic-validation)
+ [Using scratch storage efficiently in Nextflow](#nextflow-scratch-storage)

## Use nf-schema and nf-validation plugins
<a name="schema-and-validation-plugins-nextflow"></a>

**Note**  
Summary of HealthOmics support for plugins:  
v22.04 – no support for plugins
v23.10 – supports `nf-schema` and `nf-validation`
v24.10 – supports `nf-schema`
v25.10, v26.04, v26.10 – supports `nf-schema`, `nf-core-utils`, `nf-fgbio`, and `nf-prov`

HealthOmics provides the following support for Nextflow plugins:
+ For Nextflow v23.10, HealthOmics pre-installs the nf-validation@1.1.1 plugin. 
+ For Nextflow v23.10 and v24.10, HealthOmics pre-installs the nf-schema@2.3.0 plugin.
+ For Nextflow v25.10, HealthOmics pre-installs the nf-schema@2.6.1, nf-core-utils@0.4.0, nf-prov@1.7.0, and nf-fgbio@1.0.1 plugins.
+ For Nextflow v26.04 and v26.10, HealthOmics pre-installs the nf-schema@2.7.2, nf-core-utils@0.4.0, nf-prov@1.7.0, and nf-fgbio@1.0.1 plugins.
+ You cannot retrieve additional plugins during a workflow run. HealthOmics ignores any other plugin versions that you specify in the `nextflow.config` file.
+ For Nextflow v24 and higher, `nf-schema` is the new version of the deprecated `nf-validation` plugin. For more information, see [ nf-schema](https://github.com/nextflow-io/nf-schema) in the Nextflow GitHub repository.

## Specify storage URIs
<a name="storage-uris-nextflow"></a>

When an Amazon S3 or HealthOmics URI is used to construct a Nextflow file or path object, it makes the matching object available to the workflow, as long as read access is granted. The use of prefixes or directories is allowed for Amazon S3 URIs. For examples, see [Amazon S3 input parameter formats](workflows-run-inputs.md#s3-run-input-formats). 

HealthOmics partially supports the use of glob patterns in Amazon S3 URIs or HealthOmics Storage URIs. Use Glob patterns in the workflow definition for the creation of `path` or `file` channels. For the expected behavior and exact cases, see [Nextflow Handling of Glob pattern in Amazon S3 inputs](workflows-run-inputs.md#wd-nextflow-s3-formats).

## Nextflow directives
<a name="workflow-nexflow-directives"></a>

You configure Nextflow directives in the Nextflow config file or workflow definition. The following list shows the order of precedence that HealthOmics uses to apply configuration settings, from lowest to highest priority:

1. Global configuration in the config file.

1. Task section of the workflow definition.

1. Task-specific selectors in the config file.

**Topics**
+ [Task retry strategy using `errorStrategy`](#workflow-nextflow-errorStrategy)
+ [Task retry attempts using `maxRetries`](#workflow-nexflow-task-retry)
+ [Opt out of task retry using `omicsRetryOn5xx`](#workflow-nextflow-retry-5xx)
+ [Configure resource fallback with **omicsResourceFallbackOrder**](#workflow-nextflow-directive-fallback)
+ [Task duration using the `time` directive](#time-directive-nextflow)

### Task retry strategy using `errorStrategy`
<a name="workflow-nextflow-errorStrategy"></a>

Use the `errorStrategy` directive to define the strategy for task errors. By default, when a task returns with an error indication (a non-zero exit status), the task stops and HealthOmics terminates the entire run. If you set `errorStrategy` to `retry`, HealthOmics attempts one retry of the failed task. To increase the number of retries, see [Task retry attempts using `maxRetries`](#workflow-nexflow-task-retry).

```
process {
    label 'my_label'
    errorStrategy 'retry'

    script:
    """
    your-command-here
    """
}
```

For information about how HealthOmics handles task retries during a run, see [Task Retries](monitoring-runs.md#run-status-task-retries).

### Task retry attempts using `maxRetries`
<a name="workflow-nexflow-task-retry"></a>

By default, HealthOmics doesn't attempt any retries of a failed task, or attempts one retry if you configure `errorStrategy`. To increase the maximum number of retries, set `errorStrategy` to `retry` and configure the maximum number of retries using the `maxRetries` directive.

The following example sets the maximum number of retries to 3 in the global configuration.

```
process {
    errorStrategy = 'retry'
    maxRetries = 3
}
```

The following example shows how to set `maxRetries` in the task section of the workflow definition.

```
process myTask {
    label 'my_label'
    errorStrategy 'retry'
    maxRetries 3
    
    script:
    """
    your-command-here
    """
}
```

The following example shows how to specify task-specific configuration in the Nextflow config file, based on the name or label selectors.

```
process {
    withLabel: 'my_label' {
        errorStrategy = 'retry'
        maxRetries = 3
    }

    withName: 'myTask' {
        errorStrategy = 'retry'
        maxRetries = 3
    }
}
```

### Opt out of task retry using `omicsRetryOn5xx`
<a name="workflow-nextflow-retry-5xx"></a>

For Nextflow v23 and later, HealthOmics supports task retries if the task failed because of service errors (5XX HTTP status codes). By default, HealthOmics attempts up to two retries of a failed task. 

You can configure `omicsRetryOn5xx` to opt out of task retry for service errors. For more information about task retry in HealthOmics, see [Task Retries](monitoring-runs.md#run-status-task-retries).

The following example configures `omicsRetryOn5xx` in the global configuration to opt out of task retry.

```
process {
    omicsRetryOn5xx = false
}
```

The following example shows how to configure `omicsRetryOn5xx` in the task section of the workflow definition.

```
process myTask {
    label 'my_label'
    omicsRetryOn5xx = false
    
    script:
    """
    your-command-here
    """
}
```

The following example shows how to set `omicsRetryOn5xx` as task-specific configuration in the Nextflow config file, based on the name or label selectors.

```
process {
    withLabel: 'my_label' {
        omicsRetryOn5xx = false
    }

    withName: 'myTask' {
        omicsRetryOn5xx = false
    }
}
```

### Configure resource fallback with **omicsResourceFallbackOrder**
<a name="workflow-nextflow-directive-fallback"></a>

HealthOmics supports the **omicsResourceFallbackOrder** process directive to define an ordered list of accelerator (or GPU) and CPU resource profiles for a process. When the requested accelerator type is unavailable, HealthOmics automatically advances to the next profile in the list. You can include a CPU-only profile as a final option.

The following example tries `nvidia-l40s` first, then `nvidia-l4`, and finally falls back to CPU if neither accelerator is available:

```
process ALIGN {
    container 'my-registry/align-multi-arch:latest'

    omicsResourceFallbackOrder([
        [acceleratorType: 'nvidia-l40s', acceleratorCount: 1, cpus: 8, memory: '32 GB', omicsResourceWaitTimeoutInMin: 45],
        [acceleratorType: 'nvidia-l4',   acceleratorCount: 1, cpus: 8, memory: '32 GB'],
        [cpus: 32, memory: '128 GB']
    ])

    script:
    """
    your-command-here
    """
}
```

You can also set the directive in the Nextflow config file. In a config file, assign the list with `=`. You can set it at the top level of the `process` scope, which applies to every process, or inside a `withName` or `withLabel` selector. The following example sets a fallback order for every process, a different one for tasks with label `my_label`, and another for task `myTask`.

```
process {
    omicsResourceFallbackOrder = [
        [acceleratorType: 'nvidia-l4', acceleratorCount: 1, cpus: 8, memory: '32 GB'],
        [cpus: 16, memory: '64 GB']
    ]

    withLabel: 'my_label' {
        omicsResourceFallbackOrder = [
            [acceleratorType: 'nvidia-l40s', acceleratorCount: 1, cpus: 8, memory: '32 GB'],
            [cpus: 32, memory: '128 GB']
        ]
    }

    withName: 'myTask' {
        omicsResourceFallbackOrder = [
            [acceleratorType: 'nvidia-l40s', acceleratorCount: 2, cpus: 16, memory: '64 GB']
        ]
    }
}
```

If a process gets a fallback order from more than one place, HealthOmics uses the first one that applies:

1. A `withName` or `withLabel` selector in the config file that matches the process.

1. The directive in the process definition.

1. The top level of the `process` scope in the config file.

HealthOmics sets the **AWS\_HEALTHOMICS\_RESOURCE\_TYPE** environment variable in the task container. Its value is the active profile's accelerator type (for example, `nvidia-l40s`) or `cpu` for a CPU-only profile. For an expanded accelerator search profile, it is the accelerator type of the instance that the task runs on. Use it to branch your command when GPU and CPU code paths differ.

Keep the following in mind when you use the directive in Nextflow:
+ Write **memory** with one of the units B, KB, MB, GB or TB, for example `'32 GB'`. GiB, MiB and TiB are not accepted.
+ A profile that omits **cpus** or **memory** uses the process's **cpus** or **memory** directive, if set.
+ When a profile inherits **cpus** or **memory** from the process, HealthOmics applies the process's **resourceLimits** directive, which sets the maximum **cpus** and **memory**, before copying the value into the profile.
+ `${task.cpus}` and `${task.memory}` in the script show the process-level values, not the resources of the profile that ran.

For more information, see [Advanced resource configuration](advanced-resource-configuration.md), and for supported accelerator types see [Task accelerators in a HealthOmics workflow definition](task-accelerators.md).

#### Interaction with retries
<a name="workflow-nextflow-fallback-retries"></a>

If you configure retries with an error strategy (the `errorStrategy` and `maxRetries` directives), the profile that each retry uses depends on why the previous attempt failed.
+ **Insufficient-capacity failures (ICE).** HealthOmics tries each profile in the list in order. After exhausting all profiles without securing capacity, the next retry starts again from the first profile in your directive.
+ **Out-of-memory (OOM) and service failures.** The retry stays on the same profile that the previous attempt reached, rather than restarting from the first profile.

### Task duration using the `time` directive
<a name="time-directive-nextflow"></a>

HealthOmics provides an adjustable quota (see [HealthOmics service quotas](service-quotas.md)) to specify the maximum duration for a run. For Nextflow v23 and later workflows, you can also specify maximum task durations using the Nextflow `time` directive.

During new workflow development, setting maximum task duration helps you catch runaway tasks and long-running tasks. 

For more information about the Nextflow time directive, see [time directive](https://www.nextflow.io/docs/latest/reference/process.html#process-time) in the Nextflow reference.

HealthOmics provides the following support for the Nextflow time directive:

1. HealthOmics supports 1 minute granularity for the time directive. You can specify a value between 60 seconds and the maximum run duration value.

1. If you enter a value less than 60, HealthOmics rounds it up to 60 seconds. For values above 60, HealthOmics rounds down to the nearest minute.

1. If the workflow supports retries for a task, HealthOmics retries the task if it times out.

1. If a task times out (or the last retry times out), HealthOmics cancels the task. This operation can have a duration of one to two minutes.

1. On task timeout, HealthOmics sets the run and task status to failed, and it cancels the other tasks in the run (for tasks in Starting, Pending, or Running status). HealthOmics exports the outputs from tasks that it completed before the timeout to your designated S3 output location. 

1. Time that a task spends in pending status does not count toward the task duration.

1. If the run is part of a run group and the run group times out sooner than the task timer, the run and task transition to failed status.

Specify the timeout duration using one or more of the following units: `ms`, `s`, `m`,`h`, or `d`.

The following example shows how to specify global configuration in the Nextflow config file. It sets a global timeout of 1 hour and 30 minutes.

```
process {
    time = '1h30m'
}
```

The following example shows how to specify a time directive in the task section of the workflow definition. This example sets a timeout of 3 days, 5 hours, and 4 minutes. This value takes precedence over the global value in the config file, but doesn't take precedence over a task-specific time directive for `my_label` in the config file.

```
process myTask {
    label 'my_label'
    time '3d5h4m'
        
    script:
    """
    your-command-here
    """
}
```

The following example shows how to specify task-specific time directives in the Nextflow config file, based on the name or label selectors. This example sets a global task timeout value of 30 minutes. It sets a value of 2 hours for task `myTask` and sets a value of 3 hours for tasks with label `my_label`. For tasks that match the selector, these values take precedence over the global value and the value in the workflow definition.

```
process {
    time = '30m'
    
    withLabel: 'my_label' {
        time = '3h'  
    }

    withName: 'myTask' {
        time = '2h'  
    }
}
```

## Use Nextflow profiles
<a name="nextflow-profiles"></a>

Nextflow profiles are named sets of configuration settings that you can select at runtime. Define profiles in the `profiles` block of your `nextflow.config` file:

```
profiles {
    standard {
        process.cpus = 2
        process.memory = '4 GB'
    }

    production {
        process.cpus = 16
        process.memory = '64 GB'
        params.input = 's3://bucket/production-data.bam'
    }
}
```

When you start a run, specify one or more profiles using the `engineSettings` parameter. HealthOmics passes the `-profile` flag to the Nextflow engine. For more information, see [Specify Nextflow engine settings](starting-a-run.md#start-run-api-engine-settings).

```
aws omics start-run \
  --workflow-id {{workflow-id}} \
  --role-arn {{role-arn}} \
  --output-uri s3://{{bucket}}/{{prefix}}/ \
  --engine-settings '{"profile": "production"}'
```

When multiple profiles are specified (for example, `"test,docker"`), Nextflow applies them in the order they are specified in the command line. Later profiles override earlier ones for conflicting settings. For Nextflow versions lower than 26, profiles are applied in the order they are defined in the configuration file instead of command line order.

Note the following:
+ Profile support is available for all HealthOmics supported Nextflow versions.
+ Profiles can contain parameters, process directives, `includeConfig` statements, and manifest overrides (including `manifest.nextflowVersion`).
+ Explicit run parameters take precedence over profile-defined parameter values.
+ If you specify a nonexistent profile, HealthOmics returns a validation error.
+ Profiles must be defined in the workflow definition zip file. HealthOmics doesn't support fetching profile definitions from external sources.
+ If you don't specify a profile, the run uses the `standard` profile if it's defined under profiles in the workflow definition. Otherwise, the run uses the default (top-level) configuration.
+ When using profiles, we recommend pinning the Nextflow version in your workflow definition using `manifest.nextflowVersion` to ensure consistent profile application behavior across runs.

## Specify Nextflow configuration at runtime
<a name="nextflow-runtime-config"></a>

You can specify a Nextflow configuration file stored in Amazon S3 and apply it at run time with the `engineConfig` engine setting. The configuration overrides the configuration in the workflow definition, so you can change run configuration without modifying the workflow definition.

The following example configuration enables the Nextflow execution report for a run without modifying the workflow definition:

```
report {
    enabled = true
    file = '/mnt/workflow/output/report.html'
    overwrite = true
}
```

For more information about the execution report and the other built-in reports, see [Generate Nextflow execution reports](#nextflow-execution-reports).

To supply the configuration file at run time, specify its Amazon S3 URI with the `engineConfig` engine setting. For more information, see [Specify Nextflow configuration at runtime](starting-a-run.md#start-run-engine-config) in [Start a run in HealthOmics](starting-a-run.md). The following AWS CLI command starts a run with an engine configuration file:

```
aws omics start-run \
  --workflow-id {{workflow-id}} \
  --role-arn {{role-arn}} \
  --output-uri s3://{{bucket}}/{{prefix}}/ \
  --engine-settings '{"engineConfig": "s3://amzn-s3-demo-bucket/my-nextflow.config"}'
```

When you specify multiple profiles (for example, `"test,docker"`), profiles defined in the runtime configuration file take precedence over profiles declared in `nextflow.config`.

How profile order is resolved within the same file depends on your Nextflow version:
+ **Nextflow v26.04 and later with the strict syntax parser (v2)** – The order specified on the command line breaks ties between profiles defined in the same file.
+ **Nextflow versions earlier than v26.04** – Nextflow applies profiles in the order they are defined in the configuration file. Runtime configuration file profiles still take precedence over `nextflow.config` profiles.

## Export workflow-level content
<a name="exporting-workflow-content-nextflow"></a>

For Nextflow v25.10 and later, you can export files produced outside of individual tasks, such as provenance reports or pipeline DAGs. To export these files, write them to `/mnt/workflow/output/`. HealthOmics exports files placed in this directory to the `output/` prefix in your run's Amazon S3 output location.

The following example shows how to configure the `nf-prov` plugin to write a provenance report to `/mnt/workflow/output/`.

```
prov {
    formats {
        bco {
            file = "/mnt/workflow/output/pipeline_info/manifest.bco.json"
        }
    }
}
```

You can also pass this path as a parameter in your run's input JSON. This approach is common with nf-core workflows that use `params.outdir`.

```
{
    "outdir": "/mnt/workflow/output/"
}
```

## Export task content
<a name="exporting-task-content-nextflow"></a>

For workflows written in Nextflow, define a **publishDir** directive to export task content to your output Amazon S3 bucket. As shown in the following example, set the **publishDir** value to `/mnt/workflow/pubdir`. To export files to Amazon S3, the files must be in this directory.

```
 nextflow.enable.dsl=2
              
  workflow {
    CramToBamTask(params.ref_fasta, params.ref_fasta_index, params.ref_dict, params.input_cram, params.sample_name)
    ValidateSamFile(CramToBamTask.out.outputBam)
  }
  
  process CramToBamTask {
    container "<account>.dkr.ecr.us-west-2.amazonaws.com/genomes-in-the-cloud"
  
    publishDir "/mnt/workflow/pubdir"
  
    input:
        path ref_fasta
        path ref_fasta_index
        path ref_dict
        path input_cram
        val sample_name
  
    output:
        path "${sample_name}.bam", emit: outputBam
        path "${sample_name}.bai", emit: outputBai
  
    script:
    """
        set -eo pipefail
  
        samtools view -h -T $ref_fasta $input_cram |
        samtools view -b -o ${sample_name}.bam -
        samtools index -b ${sample_name}.bam
        mv ${sample_name}.bam.bai ${sample_name}.bai
    """
  }
  
  process ValidateSamFile {
    container "<account>.dkr.ecr.us-west-2.amazonaws.com/genomes-in-the-cloud"
  
    publishDir "/mnt/workflow/pubdir"
  
    input:
        file input_bam
  
    output:
        path "validation_report"
  
    script:
    """
        java -Xmx3G -jar /usr/gitc/picard.jar \
        ValidateSamFile \
        INPUT=${input_bam} \
        OUTPUT=validation_report \
        MODE=SUMMARY \
        IS_BISULFITE_SEQUENCED=false
    """
  }
```

For Nextflow v25.10 and later, as an alternative to `publishDir`, you can use workflow outputs to export task content. The following example shows how to define a workflow `output` block that exports task results to Amazon S3.

```
process myTask {
    input:
    val data

    output:
    path 'result.txt'

    script:
    """
    echo ${data} > result.txt
    """
}

workflow {
    main:
    output_file = myTask('hello')

    publish:
    results = output_file
}

output {
    results {
        path '.'
    }
}
```

For more information about workflow outputs, see [Workflow outputs](https://www.nextflow.io/docs/latest/workflow.html#workflow-output-def) in the Nextflow documentation.

## Generate Nextflow execution reports
<a name="nextflow-execution-reports"></a>

Nextflow can produce four built-in reports for each run: an execution report (`report`), a timeline (`timeline`), a trace file (`trace`), and a workflow diagram (`dag`). For HealthOmics to export these files to your run's Amazon S3 output location, configure each one to write its output under `/mnt/workflow/output/` in your `nextflow.config` file:

```
report {
    enabled = true
    file = '/mnt/workflow/output/report.html'
    overwrite = true
}

timeline {
    enabled = true
    file = '/mnt/workflow/output/timeline.html'
    overwrite = true
}

trace {
    enabled = true
    file = '/mnt/workflow/output/trace.txt'
    overwrite = true
}

dag {
    enabled = true
    file = '/mnt/workflow/output/dag.html'
    overwrite = true
}
```

HealthOmics exports files written under `/mnt/workflow/output/` to the `output/` prefix in your run's Amazon S3 output location. For more information about this export path, see [Export workflow-level content](#exporting-workflow-content-nextflow). Reports written outside `/mnt/workflow/output/` are not exported to your run's Amazon S3 output location.

**Nextflow v26.10 and later.** You can also place the `report`, `timeline`, `trace`, and `dag` files with the scope's `directory` option, for example `report.directory = 'pipeline_info'`. The `directory` value must be a relative path. Nextflow writes the files under the workflow's `outputDir`, and HealthOmics exports them with the run outputs. If you also set `file`, use a file name only. Reports that set only a relative `file` path, without `directory`, are not exported. File names include a timestamp unless you set `file`.

**Task containers must include `ps`**  
When the `report`, `timeline`, or `trace` report is enabled, Nextflow collects per-task metrics by invoking `ps` inside each task container. The container image that you specify with the `container` directive must include the `ps` command. On most Linux distributions, install it with the `procps` (Debian/Ubuntu) or `procps-ng` (Amazon Linux, Red Hat, Fedora) package. If a process does not declare a `container` directive, HealthOmics runs the task in a default container that already includes `ps`.

**Workflow diagram format**  
The `dag` report supports several output formats, selected by the extension of `dag.file`. The HTML, Mermaid, and DOT formats are rendered directly by Nextflow and do not require additional tooling. The PDF, PNG, and SVG formats require Graphviz, which is not included in HealthOmics's Nextflow engine. If `dag.file` is set to a PDF, PNG, or SVG path, Nextflow logs a warning and writes the workflow diagram as a `.dot` source file in its place; the run still completes successfully. We recommend setting `dag.file` to a `.html`, `.mmd`, or `.dot` path to avoid the warning and produce the requested format.

## Specify the Nextflow syntax version
<a name="nextflow-syntax-version"></a>

Nextflow v26.04.0 and later use the strict (v2) syntax parser by default. This is a breaking change for workflows written using the legacy (v1) syntax, which is the default in Nextflow v25.10.0 and earlier. For information about the v2 syntax, see [Strict syntax](https://docs.seqera.io/nextflow/strict-syntax) in the Seqera Nextflow documentation.

To run a workflow authored against the legacy (v1) parser, set `engineSettings.syntaxVersion` to `v1` in the **StartRun** request:

```json
{
  "engineSettings": {
    "syntaxVersion": "v1"
  }
}
```

For Nextflow v25.10.0 and earlier, HealthOmics does not support the v2 parser.

## Automatic syntax validation during workflow creation
<a name="nextflow-automatic-validation"></a>

HealthOmics automatically runs the Nextflow built-in strict DSL2 linter (nf-lang/v2) when you create or update a Nextflow DSL2 workflow. This linter runs during `CreateWorkflow` and `CreateWorkflowVersion`. It applies to all supported DSL2 versions (v22.04, v23.10, v24.10, v25.10, v26.04, and v26.10). DSL1 workflows are not linted.

The linter operates in non-blocking mode. Lint findings don't prevent the workflow from becoming ACTIVE. Findings appear as structured JSON in the `statusMessage` field of the `GetWorkflow` response.

**Note**  
The built-in linter validates your workflow definition syntax at creation time. It is distinct from the strict syntax *parser* available for Nextflow v26.04 and later, which is controlled by `engineSettings.syntaxVersion` and affects runtime behavior. The linter checks syntax across all DSL2 versions at creation time, regardless of which parser the workflow uses at runtime. On Nextflow v22.04, v23.10, and v24.10 (legacy grammar), findings are advisory. On Nextflow v25.10, v26.04, and v26.10, findings reflect strict mode syntax requirements. For workflows that declare Nextflow v26.10 in `manifest.nextflowVersion`, validation uses the v26.10 linter, which also reports static type errors for scripts that enable static typing.

For more information about the lint output format and how to address findings, see [Workflow linters in HealthOmics](workflows-linter.md).

## Using scratch storage efficiently in Nextflow
<a name="nextflow-scratch-storage"></a>

Nextflow's `scratch` directive controls where a process writes its temporary working files. When ephemeral storage is enabled (`scratchStorageMode: LOCAL`), use the `scratch` directive to direct scratch I/O to the fast local volume at `/tmp`.

The following table describes the supported `scratch` directive values and their behavior in HealthOmics:


| Value | Behavior in HealthOmics | Recommendation | 
| --- | --- | --- | 
| scratch true | Uses $TMPDIR. Scratch I/O is directed to the local ephemeral volume when scratchStorageMode is LOCAL. | Recommended | 
| scratch '/some/path' | Uses the specified literal path as the scratch directory. To use ephemeral storage, set the path to /tmp or a subdirectory of /tmp. The path must exist in the container and be writable. | Works when path is under /tmp | 
| scratch 'ram-disk' | Attempts to use /dev/shm (tmpfs in RAM). This is not recommended for local scratch storage in HealthOmics. | Not recommended | 

The recommended approach is to set `scratch true` in your process definition, which automatically uses `$TMPDIR` and requires no path configuration:

```
process my_process {
    scratch true
    disk '200 GB'
    script:
    """
    my-tool --input ${input} --output ${output}
    """
}
```

For more information about ephemeral storage and the `disk` directive, see [Ephemeral storage for HealthOmics workflow tasks](workflows-ephemeral-storage.md).