Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Bash path configurable #5696

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

pditommaso
Copy link
Member

This PR allows the customisation of Bash interpreter used by Nextflow go a user provided path defined via nextflow config file or an environment variable (to be done).

Signed-off-by: Paolo Di Tommaso <[email protected]>
Copy link

netlify bot commented Jan 22, 2025

Deploy Preview for nextflow-docs-staging canceled.

Name Link
🔨 Latest commit c0e2aa7
🔍 Latest deploy log https://app.netlify.com/sites/nextflow-docs-staging/deploys/67911736f4a1a60008b0023f


@Memoized
static String bash() {
session().config.navigate('nextflow.defaults.bash') ?: '/bin/bash'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This config scope was renamed to workflow, I would just call it workflow.bash

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's discuss about this. I think we need to nextflow wide setting (more tied to runtime than workflow concept)

Comment on lines -87 to +88
BASH = Collections.unmodifiableList( level > 0 ? ['/bin/bash','-uex'] : ['/bin/bash','-ue'] )

BASH = Collections.unmodifiableList( level > 0 ? [NF.bash(), '-uex'] : [NF.bash(), '-ue'] )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This use of NF.bash() makes me think that the user bash setting can only be the bash path itself and can't include extra arguments like env -S bash or bash -o pipefail. Will that be acceptable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal should be to specify a custom Bash path not to alter the shell option. That's possible in some extent via process.shell

@@ -84,8 +85,7 @@ class BashWrapperBuilder {
catch( Exception e ) {
log.warn "Invalid value for `NXF_DEBUG` variable: $str -- See http://www.nextflow.io/docs/latest/config.html#environment-variables"
}
BASH = Collections.unmodifiableList( level > 0 ? ['/bin/bash','-uex'] : ['/bin/bash','-ue'] )

BASH = Collections.unmodifiableList( level > 0 ? [NF.bash(), '-uex'] : [NF.bash(), '-ue'] )
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that BASH is used for both running the task on the host as well as within the container. This means NF.bash should be something that is acceptable in both situations (OR: one has to change the profile and NF.bash at the same time if one needs to use different interpreters depending on whether the task runs on a host or on a container). I also understand that /bin/bash is the only official entry point to run docker containers.

Maybe for some context, here is a test script that I am using to check whether the Nextflow package is running as expected on NixOS. I'm linking this here to show what my goal is/was with #5684. (The test is easy to understand without knowledge of Nix.). 5684 would allow me to pass this test.

I think even today, I could use an unpatched Nextflow on NixOS if I "simply" adapt process.shell everywhere. Tracing might not work. I'd like to improve on that situation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means NF.bash should be something that is acceptable in both situations

Yes, that's correct.

I think even today, I could use an unpatched Nextflow on NixOS if I "simply" adapt process.shell everywhere. Tracing might not work. I'd like to improve on that situation.

my understanding is that in NixOS the Bash interpreter is located at /usr/bin/bash so this PR should solve the problem with a minimal setting.

Is it not the case?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NixOS has bash at /run/current-system/sw/bin/bash but the correct way to invoke it is /usr/bin/env -S bash.

But: The docker images doesn't have it there. They have it (officially) at /bin/bash. My whole point is that I want the system to not use the same (path to) bash in both cases (docker execution vs host execution). Let me write a another comment to explain the situation below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. What's preventing creating a symlink to "normalise" it?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A Nix package cannot create arbitrary files on the file system. Actually, older definitions of the Nextflow package used a wrapper to make nextflow believe that /bin/bash exists. However, using this wrapper comes with other drawbacks.

Signed-off-by: Paolo Di Tommaso <[email protected]>
@rollf
Copy link

rollf commented Jan 22, 2025

Thank you for addressing my issues @pditommaso.

NixOS currently patches Nextflow so that it can run there even though /bin/bash is not available. This works great unless one wants to enable tracing. Instead of improving the patch, I thought it might be nice to solve the issue upstream. Hence my motivation for #5432. I closed that PR in favor of #5684 (because the latter is more clean and I also updated my initial implementation since #4209 got merged in the meantime).

Now, #5684 got also closed and my approach will not be merged (reasoning is mentioned here) in favor of this PR here. I believe this PR here does not improve the situation for NixOS (see my reasoning here and here).

Thus, I see two options now

  • Either: I'm wrong and this PR here does indeed improve the situation for NixOS in all 4 scenarios (docker on/off x tracing on/off) with minimal additional patching/configuration upfront but without having to touch the actual pipeline and without having to change process.shell when enabling/disabling docker/tracing.
  • Or: This PR here does not help and I thus suggest to not merge if it was only motivated by supporting NixOS (since Nextflow doesn't need it). The Nix package definition for Nextflow will then continue to patch vanilla Nextflow; the patch will of course be improved to allow the tracing scenario (i.e. simply derive a patch from Use /usr/bin/env -S bash instead of /bin/bash on the host system #5684 and apply it).

I can test option 1) but would need advice how you envision this to be used. However, we might also directly agree on option 2).

(For option 2, it would make my life easier if this PR here does not get merged. But this is of course entirely up to others to decide)

@pditommaso pditommaso marked this pull request as draft January 23, 2025 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants