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

underlying parse failure on coproc with group/braced command-list form #79

Open
tejing1 opened this issue Apr 16, 2022 · 4 comments
Open

Comments

@tejing1
Copy link

tejing1 commented Apr 16, 2022

nix-repl> pkgs.resholve.version                                                                                                                           
"0.8.0"

nix-repl> :b pkgs.resholve.writeScript "foo" { interpreter = "${pkgs.bash}/bin/bash"; inputs = [];} "coproc TEST { echo foo; }; cat </dev/fd/\${TEST[0]}"
error: builder for '/nix/store/vf27cqizwz0274k8dzlvrczcbzmph14g-foo.drv' failed with exit code 1;
       last 8 log lines:
       > [resholve context] : invoking resholve with PWD=/build
       > [resholve context] RESHOLVE_LORE=/nix/store/a9sjzsny6c1hfz9764h0522cpgzhq4xi-more-binlore
       > [resholve context] RESHOLVE_INPUTS=
       > [resholve context] RESHOLVE_INTERPRETER=/nix/store/30j23057fqnnc1p4jqmq73p0gxgn0frq-bash-5.1-p16/bin/bash
       > [resholve context] /nix/store/illp9406jkdy0yncvh4l8x9qw8r7c8jk-resholve-0.8.0/bin/resholve --overwrite /nix/store/lisy9259fqy5vsa7g7gk863qj6wqsgdr-foo
       >   coproc TEST { echo foo; }; cat </dev/fd/${TEST[0]}
       >                           ^
       > /nix/store/lisy9259fqy5vsa7g7gk863qj6wqsgdr-foo:2: error: Unexpected right brace
       For full logs, run 'nix log /nix/store/vf27cqizwz0274k8dzlvrczcbzmph14g-foo.drv'.
$ bash -c 'coproc TEST { echo foo; }; cat </dev/fd/${TEST[0]}'
foo
@abathur
Copy link
Owner

abathur commented Apr 16, 2022

This is one of the cases where the OSH/Oil parser doesn't support it, and unless maybe we convince upstream to do it (or patch and maintain it...) we're a little stuck.

$ osh -c 'coproc TEST { echo foo; }; cat </dev/fd/${TEST[0]}'
  coproc TEST { echo foo; }; cat </dev/fd/${TEST[0]}
                          ^
[ -c flag ]:1: Unexpected right brace

I had informally reported this to Andy on the Oilshell Zulip before and he indicated that he wasn't planning to support this coproc form because it seemed like it was out in the long tail. (It's a fairly recent feature, he couldn't find many uses out in real-world programs/scripts, etc.)

I went ahead and opened an issue at oils-for-unix/oils#1108. Real-world use is more likely to sway Andy, so if you boiled this down from something you found in the wild, it might help to link to the script that uses it in that issue. :)

@abathur abathur changed the title Failure to parse coproc with group command underlying parse failure on coproc with group/braced command-list form Apr 16, 2022
@tejing1
Copy link
Author

tejing1 commented Apr 16, 2022

I suppose that depends on what qualifies as 'the wild'. I was using it in a personal script, so I got around the problem by rewriting it a bit. Fortunately in this case I could make it work with the unnamed simple command form. I do slightly prefer having it named, but I don't actually need it to be. I have to admit, it is a pretty uncommonly-used feature.

The script (template) I was converting is here: https://github.com/tejing1/nixos-config/blob/45d10ed6c530f80abf19e7c8e1cb028de3ebdb92/homeConfigurations/tejing/email/mailwatch.sh#L15. Don't mind the @foo@ stuff. That currently gets processed into nix storepaths by a custom system which I want to phase out in favor of resholve.

@abathur
Copy link
Owner

abathur commented Apr 16, 2022

Ah. I may be mis-remembering. It's actually the use of [name] that causes this and not the braces, yeah?

Nope. Braces. Phew :)

@abathur
Copy link
Owner

abathur commented Apr 16, 2022

I'll link yours upstream. It's at least a real example. :)

I wrestled with this general issue a bit when I wrote lilgit; I currently try to have my cake and eat it by using the unnamed form and then copy it https://github.com/abathur/lilgit/blame/main/lilgit.bash#L3-L7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants