abathur / resholve

a shell resolver? :) (find and resolve shell script dependencies)
MIT License
231 stars 5 forks source link

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

Open tejing1 opened 2 years ago

tejing1 commented 2 years ago
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 commented 2 years ago

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 https://github.com/oilshell/oil/issues/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. :)

tejing1 commented 2 years ago

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 commented 2 years ago

~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 commented 2 years ago

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.