Announcement and recommendations for updating nf-core/configs Nextflow strict syntax compliant
Introduction
From 26.04, Nextflow will make its new ‘Strict Syntax’ mode default.
It is a more restrictive way of writing Nextflow that improves error messages and makes the code more consistent.
This page describes ways to make your config syntax compliant. For example, for nf-core/configs.
Check for strict syntax compliance
There are two ways to check if your existing config is compliant with the new strict syntax.
In both cases, you need a local copy of the nf-core/configs repository (ideally as a fork on a separate branch if you need to make changes).
VS Code
VS Code with the Nextflow extension is the easiest way to check for problems with your config.
To check your config with the Nextflow VS Code extension:
Open the nf-core/configs repo as a VS Code project
If you don’t use VSCode, you can instead use Nextflow itself on the command line.
[!WARNING]
This does not check the config functionality works!
See end of instructions
The fastest way to test whether your config is Nextflow strict syntax compliant is to make an empty workflow, and run it using your config as a custom config file.
For example:
In your local copy of fork of nf-core/configs, make a file called main.nf
echo "workflow{}" > main.nf
Run the minimal workflow with the latest edge version of Nextflow (26.02.0-edge) and pointing to the config file you want to test
NXF_VER=26.02.0-edge nextflow run main.nf -c conf/<your_config>.config
If you have no warning or errors messages, you are good to go - your config is already compliant!
If you have messages, see the next section on how to resolve the most common errors.
Common fixes
This section describes common fixes and solutions seen across existing nf-core/configs.
Simple variables
Problem
Variables are not allowed in the configs under the strict syntax.
If you get an error like:
Error <config_name>.config:1:1: Variable declarations cannot be mixed with config statements
If your config use variables that are ‘simple’, i.e. static values scratch_dir = ''/ptmp', continue reading this section.
If you have more complicated variables (e.g. variables with a condition inside), see Dynamic variables.
Solution
You will need to convert the variable to a parameter.
Check if the variable is actually used multiple times.
If it isn’t, then remove the variable entirely, and just directly use the contents of the variable where the variable was being used.
If the variable is used multiple times, you can convert the variable to a parameter. For example:
[!WARNING]
Make sure the parameter names are unique and isolated to the config so they don’t overwrite anything in any pipelines themselves!
We recommend: <config_name>_<variable_name>, but feel free to make it more unique.
To prevent nf-schema warnings during pipeline initialisation, you should also add the following to your config:
Variables are not allowed in the configs under the strict syntax.
If you get an error like:
Error <config_name>.config:1:1: Variable declarations cannot be mixed with config statements
If your config uses variables that are dynamic (e.g. variables with a condition inside), continue reading this section.
If your config uses variables that are ‘simple’, i.e. static values scratch_dir = ''/ptmp', see Simple variables.
Solution
You will need to convert these variables to a parameter.
Check if the code could not be converted to a ternary one-liner, e.g.
[!WARNING]
Don’t forget to set the .call() here at the end.
This makes sure the code is evaluated during config resolution.
If you don’t add .call(), the parameter will be a closure instead of the expected value.
To prevent nf-schema warnings during pipeline initialisation, you should also add the following to your config:
Try to refactor your code to not use any functions.
[!WARNING]
We do not currently have a good solution to this, due to a conflict with nf-schema used for pipeline input validation!
Our only solution is to repeatedly implement the code at each use of the function within a closure.
All functions should be converted to callable closures that are assigned to a parameter.
This is similar to using ternary operators but less readable.
This is discouraged for simple if-statements, however you can use this in cases of more complex conditions.
It’s up to the config developer to decide when to use what method.
Once you have made your changes and you have tested with the basic workflow, it is HIGHLY recommended to test the updated config on a real nf-core pipeline.
If you are updating the config on a fork or branch, you can use the two parameters:
--custom_config_version: to specify a different branch (e.g. on a branch within nf-core/configs)
--custom_config_base: to specify a different fork
For example, for a fork:
nextflow pull nf-core/demoNXF_VER=26.02.0-edge nextflow run nf-core/demo -profile test,<config name> --custom_config_base 'https://github.com/<your user name>/nf-core-configs/raw/refs/heads/<your branch name>/nfcore_custom.config'