-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Output of print-dev-env
has a syntax error
#10263
Comments
Fixes syntax errors when using `use flake`, see also NixOS/nixpkgs#296936 NixOS/nix#10263 direnv/direnv#1256
Yeah, Nix does some funky bash magic to only dump the declared environment variables and functions (and not the whole stdenv script). So that doesn't include the checking snippet that you link (that snippet does run internally, but using the Few ideas to solve this:
Option 3. seems to be the most reasonable one. Thoughts? |
Yes, I agree, something like option 3 seems reasonable. I was thinking that maybe Nix could look for a special But then the syntax of that would have to be compatible with absolutely everything, and if it is defined multiple times, that has to be handled, it could be abused for something the derivations are intended for, it just opens a whole can of worms for something that is already an edge case. Specifying something like |
If we can avoid using bash 4 features, it is preferable to use (3) to avoid the need for workarounds that may confuse newcomers. |
I understand where @domenkozar is coming from: MacOS still ships Bash 3.2 and unless you've installed bash from either Brew or Nix, you'll still get that version in your profile. That being said: Bash 3.2 is from 2006. I think increasing the supported revision to bash4 and explicitly stating that dependency is a good option. It isn't like MacOS users can't upgrade. We just might want to make upgrade instructions clear and targeted in the error message (as I cannot believe that there's a lot of Linux distributions shipping bash3 by default any more). |
@iFreilicht : Can you handle the Nixpkgs part of this? Once that's done, I can do the Nix-side bits |
Relates to NixOS/nix#10263 and NixOS#296936 This will help external tools (Nix and direnv for now) perform the same version check setup.sh is already doing when building.
@thufschmitt Done! See NixOS/nixpkgs#299490 |
To be fully honest, I think none of that should even exist in Nix. See #4702 (comment) and #7501. If Nixpkgs maintainers or users of |
To me, I do agree that more of the logic could move into nixpkgs here, but right now I feel improving the error message here matters most. I'm completely fine with all this getting ripped out again if we ever find a good abstraction that allows |
Allow derivations to export a `NIX_ENV_MIN_BASH_VERSION` that sets the minimal (major) bash version that is required to parse their setup script, and use that to gracefully fail if the current bash is too old. Fix NixOS#10263
Allow derivations to export a `NIX_ENV_MIN_BASH_VERSION` that sets the minimal (major) bash version that is required to parse their setup script, and use that to gracefully fail if the current bash is too old. Fix #10263 (from the Nix side at least, needs NixOS/nixpkgs#299490 from the Nixpkgs side to be useful in practice)
Thanks @iFreilicht ! I've opened #10359 for the Nix side @fricklerhandwerk I tend to agree, but it's here right now, so we definitely shouldn't keep it broken |
I surely won't block, this is just my humble opinion, but we totally can decidedly ignore the issue – arguing that we'd rather prioritise stable API quality, testing, contributor experience etc., re-iterating that experimental commands are called that for a reason, and hand over the responsibility to those who care enough about this particular feature to implement it where it would be suited better anyway. Not doing that would, also in my humble opinion, be inconsistent with what we already have in writing; especially since we have a track record of not actually focusing on what we claimed we wanted to. |
Describe the bug
Using a very simple flake that contains nothing but an empty devShell, running
nix print-dev-env
will output a bash script that contains a syntax error. Trying to run the bash script will result in the following error:Steps To Reproduce
nix flake new asdf
cd asdf
flake.nix
with:git add .
nix run github:NixOS/nix#nix print-dev-env | bash
to see the error:Expected behavior
A clear and concise description of what you expected to happen.
nix-env --version
outputAdditional context
This is only an issue with bash 3.x. 4.0+ works fine. So this only affects darwin users, and only some other tool tries to source the file with the system bash (like it happened for me, see NixOS/nixpkgs#296936)
The full output is here: faulty.sh
The relevant context around line 1604 is this:
Nixpkgs is aware that the script is only compatible with bash 4.0+, and so
setup.sh
specifically has this check to prevent exactly the error we see above:But for some reason, it's not included in the output of
print-dev-env
. I assume there would have to be a hook function defined so that nix can find it in the intermediate environment and include (and call it) in the output.Priorities
Add 👍 to issues you find important.
The text was updated successfully, but these errors were encountered: