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

fix shell in ammonite package #68151 #73905

Merged
merged 1 commit into from Dec 1, 2019
Merged

fix shell in ammonite package #68151 #73905

merged 1 commit into from Dec 1, 2019

Conversation

bbjubjub2494
Copy link
Member

@bbjubjub2494 bbjubjub2494 commented Nov 22, 2019

Motivation for this change

The amm command doesn't work when started from the fish shell because it lacks a shebang.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions (Arch Linux with Arch Linux provided fish)
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip" No diff detected
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after) +8 bytes
  • Ensured that relevant documentation is up to date Nothing to update AFAICT
  • Fits CONTRIBUTING.md.
Notify maintainers

cc @NeQuissimus

Upstream doesn't include a shebang line but recommends adding one at
installation time. NixOS users noticed that the command wouldn't exec
when using certain shells.
@ghost
Copy link

ghost commented Nov 22, 2019

Have you considered using #!/usr/bin/env bash because #!/bin/sh is not always bash. Otherwise 👍 LGTM

@bbjubjub2494
Copy link
Member Author

Have you considered using #!/usr/bin/env bash because #!/bin/sh is not always bash. Otherwise LGTM

Good question. Upstream recommends /usr/bin/env sh (oddly enough) as a shebang. The shell script[1] looks like it's meant to not only work with any POSIX sh but also with batch.exe. It's very short because the rest of the file is in fact the JAR and I don't see any bashisms. To test this hypothesis further, I passed it to dash and surely enough, ammonite started as usual. Thus I think /bin/sh is appropriate.

[1]

@ 2>/dev/null # 2>nul & echo off & goto BOF
:
exec /nix/store/qdb4a4qww23a6cb408qi5r7ypmk1c6dp-openjdk-8u222-ga-jre/bin/java -Xmx500m -XX:+UseG1GC $JAVA_OPTS -cp "$0" ammonite.Main --no-remote-logging "$@"
exit

:BOF
@echo off
java -Xmx500m -XX:+UseG1GC %JAVA_OPTS% -cp "%~dpnx0" ammonite.Main %*
exit /B %errorlevel%
PK
... rest of the jar

@flokli flokli changed the title fix #68151 fix shell in ammonite package #68151 Nov 25, 2019
@bbjubjub2494
Copy link
Member Author

I ticked "Tested using sandboxing" because I realised it was on the whole time.

nix-review says No diff detected, stopping review...

Package closure size:

Before
/nix/store/xmap6fl3rglvczvgz946fp83l4mh2wna-ammonite-1.7.4	  431872784
After
/nix/store/2irpkws16m4bbsykzmg8dknapjix59qn-ammonite-1.7.4	  431872792

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-in-distress/3604/14

@lilyball
Copy link
Member

lilyball commented Dec 1, 2019

I've tested this on macOS. Seems to work.

> nix-shell -E 'with import ./default.nix {}; mkShell { buildInputs = [ ammonite fish ]; }'
these derivations will be built:
  /nix/store/3gzk5ycx0akp04jr1hfhw5ppmns15ww8-ammonite-1.7.4.drv
these paths will be fetched (293.54 MiB download, 1103.47 MiB unpacked):
  […]

[nix-shell:~/Dev/Nix/nixpkgs]$ fish
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
fish prompt> amm
Loading...
Compiling (synthetic)/ammonite/predef/interpBridge.sc
Compiling (synthetic)/ammonite/predef/replBridge.sc
Compiling (synthetic)/ammonite/predef/sourceBridge.sc
Compiling (synthetic)/ammonite/predef/frontEndBridge.sc
Compiling (synthetic)/ammonite/predef/DefaultPredef.sc
Welcome to the Ammonite Repl 1.7.4
(Scala 2.13.1 Java 1.8.0_222)
If you like Ammonite, please support our development at www.patreon.com/lihaoyi
@

@NeQuissimus NeQuissimus merged commit 37c644e into NixOS:master Dec 1, 2019
@bbjubjub2494 bbjubjub2494 deleted the master+fix_68151 branch December 1, 2019 14:36
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.

None yet

5 participants