diff --git a/modules/nextflow/src/main/groovy/nextflow/config/ConfigBuilder.groovy b/modules/nextflow/src/main/groovy/nextflow/config/ConfigBuilder.groovy index 765aa43374..7fc04979f6 100644 --- a/modules/nextflow/src/main/groovy/nextflow/config/ConfigBuilder.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/config/ConfigBuilder.groovy @@ -77,6 +77,8 @@ class ConfigBuilder { Map emptyVariables = new LinkedHashMap<>(10) + Map env = new HashMap<>(System.getenv()) + List warnings = new ArrayList<>(10); { @@ -205,6 +207,7 @@ class ConfigBuilder { /** * Config file in the pipeline base dir + * This config file name should be predictable, therefore cannot be overridden */ def base = null if( baseDir && baseDir != currentDir ) { @@ -217,8 +220,10 @@ class ConfigBuilder { /** * Local or user provided file + * Default config file name can be overridden with `NXF_CONFIG_FILE` env variable */ - def local = currentDir.resolve('nextflow.config') + def configFileName = env.get('NXF_CONFIG_FILE') ?: 'nextflow.config' + def local = currentDir.resolve(configFileName) if( local.exists() && local != base ) { log.debug "Found config local: $local" result << local diff --git a/modules/nextflow/src/test/groovy/nextflow/config/ConfigBuilderTest.groovy b/modules/nextflow/src/test/groovy/nextflow/config/ConfigBuilderTest.groovy index 4d44a522bf..a8c51ef482 100644 --- a/modules/nextflow/src/test/groovy/nextflow/config/ConfigBuilderTest.groovy +++ b/modules/nextflow/src/test/groovy/nextflow/config/ConfigBuilderTest.groovy @@ -280,6 +280,45 @@ class ConfigBuilderTest extends Specification { folder?.deleteDir() } + + def 'should fetch the config path from env var' () { + given: + def folder = File.createTempDir() + def configMain = new File(folder,'my.config').absoluteFile + + + configMain.text = """ + process.name = 'alpha' + params.one = 'a' + params.two = 'b' + """ + + // relative path to current dir + when: + def config = new ConfigBuilder(env: [NXF_CONFIG_FILE: 'my.config']) .setCurrentDir(folder.toPath()) .build() + then: + config.params.one == 'a' + config.params.two == 'b' + config.process.name == 'alpha' + + // absolute path + when: + config = new ConfigBuilder(env: [NXF_CONFIG_FILE: configMain.toString()]) .build() + then: + config.params.one == 'a' + config.params.two == 'b' + config.process.name == 'alpha' + + // default should not find it + when: + config = new ConfigBuilder() .build() + then: + config.params == [:] + + cleanup: + folder?.deleteDir() + } + def 'CLI params should overrides the ones in one or more profiles' () { setup: