Repository navigation
Description
Describe the bug
I'm using nextflow, as packaged in #339197, from the current unstable channel. This new packaging of nextflow has a patch to make sure the correct paths to bash is used depending on whether docker is enabled for the nextflow workflow run or not:
nixpkgs/pkgs/development/interpreters/nextflow/default.nix
Lines 36 to 45 in ccc0c21
| postPatch = '' | |
| # Nextflow invokes the constant "/bin/bash" (not as a shebang) at | |
| # several locations so we fix that globally. However, when running inside | |
| # a container, we actually *want* "/bin/bash". Thus the global fix needs | |
| # to be reverted for this specific use case. | |
| substituteInPlace modules/nextflow/src/main/groovy/nextflow/executor/BashWrapperBuilder.groovy \ | |
| --replace-fail "['/bin/bash'," "['${bash}/bin/bash'," \ | |
| --replace-fail "if( containerBuilder ) {" "if( containerBuilder ) { | |
| launcher = launcher.replaceFirst(\"/nix/store/.*/bin/bash\", \"/bin/bash\")" | |
| ''; |
N E X T F L O W ~ version 24.08.0-edge
Launching `main.nf` [awesome_cori] DSL2 - revision: 5ad587431e
executor > local (1)
[56/9687f5] sayHello (1) [100%] 1 of 1, failed: 1 ✘
ERROR ~ Error executing process > 'sayHello (1)'
Caused by:
Process `sayHello (1)` terminated with an error exit status (127)
...
Command error:
.command.run: line 154: /nix/store/717iy55ncqs0wmhdkwc5fg2vci5wbmq8-bash-5.2p32/bin/bash: No such file or directory
Work dir:
/home/stian/devp/hello/work/56/9687f5d5b119c156ba9a46e4694428
...The problem is in the .command.run file, where not all occurrences of paths to bash is handled correctly by the postPath. When I enable tracing in addition to docker, then the command in .command.run changes from this:
docker run -i --cpu-shares 1024 -e "NXF_TASK_WORKDIR" -e "NXF_DEBUG=${NXF_DEBUG:=0}" -v /home/stian/devp/hello/work/56/9687f5d5b119c156ba9a46e4694428:/home/stian/devp/hello/work/56/9687f5d5b119c156ba9a46e4694428 -w "$NXF_TASK_WORKDIR" --name $NXF_BOXID quay.io/nextflow/bash /bin/bash /home/stian/devp/hello/work/56/9687f5d5b119c156ba9a46e4694428/.command.runto this:
docker run -i --cpu-shares 1024 -e "NXF_TASK_WORKDIR" -e "NXF_DEBUG=${NXF_DEBUG:=0}" -v /home/stian/devp/hello/work/56/9687f5d5b119c156ba9a46e4694428:/home/stian/devp/hello/work/56/9687f5d5b119c156ba9a46e4694428 -w "$NXF_TASK_WORKDIR" --name $NXF_BOXID quay.io/nextflow/bash /bin/bash /home/stian/devp/hello/work/56/9687f5d5b119c156ba9a46e4694428/.command.run nxf_traceThe addition of nxf_trace at the end there takes the bash script into the function nxf_trace_linux (or nxf_trace_mac is on mac), where there's a hardcoded path to the nix store-provided bash:
nxf_trace_linux() {
...
/nix/store/717iy55ncqs0wmhdkwc5fg2vci5wbmq8-bash-5.2p32/bin/bash -ue /home/stian/devp/hello/work/56/9687f5d5b119c156ba9a46e4694428/.command.sh &
...This nix store-provided bash path should not be there as I enabled docker, but it remains, and causes the process to fail.
An additional occurrence of the nix store-provided bash path is present in the shebang of the .command.sh file, although it makes no difference to the result of the workflow run.
Steps To Reproduce
Steps to reproduce the behavior:
- Create a shell with nextflow as packaged in nextflow: 22.10.6 -> 24.08.0-edge + remove buildFHSEnv + compile from source + add tests #339197
- Download the example workflow https://github.com/nextflow-io/hello, or use any other workflow and enable both docker and tracing.
- Run the workflow and observe that you get an error similar to the above.
Expected behavior
I expected the workflow run to succeed, and that the files .command.run and .command.sh should have no occurrences of paths to the nix store.
Screenshots
NA
Additional context
NA
Notify maintainers
Metadata
[stian@stian-dell-nixos:~/devp/hello]$ nix-shell -p nix-info --run "nix-info -m"
- system: `"x86_64-linux"`
- host os: `Linux 6.6.56, NixOS, 24.05 (Uakari), 24.05.20241016.e001b23`
- multi-user?: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.18.8`
- nixpkgs: `/nix/store/apchqa88gf3yp1fghqn9aqkg0c2fm962-source`
Activity
stianlagstad commentedon Oct 21, 2024
Here's a change which will add two more test cases, leading to failures:
rollf commentedon Oct 21, 2024
@stianlagstad Thank you for the detailed report. I vaguely remember that I had looked into the traced-scenario and that something was problematic but I must have lost attention. Sorry about that. I'll have a look into this.
stianlagstad commentedon Oct 22, 2024
Please don't apologize! Thank you again for the good work in #339197 💯
I'm trying myself to iterate on a modified
postPatch, but so far I have not been successful. I'm considering writing a PR for the nextflow repository instead, so that we can avoid the hardcoded/bin/bashstrings there.Update: I've created an issue for this on the nextflow side: nextflow-io/nextflow#5420
rollf commentedon Oct 22, 2024
Ah, yes, me, too :) I have something working already see here but I'm not totally satisfied. I will iterate and then open a PR upstream.
rollf commentedon Oct 22, 2024
Okay, I updated my nextflow-patch and also created a nixpkgs branch that uses this new version and doesn't need to patch anything anymore. You should be able to run it like so
(Mind that it's a newer version of nextflow).
Would be great if you could try this out.
I have adapted the NixOS-tests based on your suggestions (see here) and they pass.
If we're both satisfied, I'll open a PR upstream as well as for nixpkgs. Let's see whether we can get that integrated into upstream.
stianlagstad commentedon Oct 23, 2024
Thank you @rollf !
Do I understand this correctly?
/usr/bin/envto see where bash is on the host, and also use it within the container to figure out where bash is thereIf I understand that correctly then there are some objections to this (using
/usr/bin/env) in the comments here:I also pointed to those in my issue in the nextflow repo: nextflow-io/nextflow#5420.
I can confirm however that your fix works for my use case.
rollf commentedon Oct 25, 2024
Yes.
Yes, I had read those except the issue you raised, so thanks for pointing them out again. I still think what I propose is reasonable because a) it does keep
/bin/bashwherever possible (and certainly within container instances) and b) the patch set is really small.Okay, I'll open a PR upstream. If it does not get accepted, then we'll need to keep the patch within nixpkgs 🤷 .
rollf commentedon Oct 25, 2024
Here is the upstream PR. We'll have to wait for CI, too.
rollf commentedon Oct 26, 2024
@stianlagstad I have spent much more time now to improve both on the nextflow as well as on the Nixpkgs side and updated both branches / the upstream PR.
hxtmdev commentedon Aug 20, 2025
Thanks for putting in the time to create a proper solution!
In the meantime, if anyone finds their way here looking for a minimal workaround to just "make it run, on Kubernetes, now", here's my current workaround:
just use
as the package with
k8s_bash.patchbeing