Open fmap opened 9 years ago
Closing due to lack of interest.
IMO such enhancement wishes can be kept open, as long as they are still meaningful.
Agreed. People are busy and lots of people want lots of different things, but it doesn't mean these things aren't important.
Fair.
I have the same problem with scala. The following doesn't work unfortunately:
#! /usr/bin/env nix-shell
#! nix-shell -i scala -p scala
object Test {
def main(args:Array[String]) {
println("Hello world!")
}
}
Any suggested workarounds?
this works for scala, it strips the bash portion of the file and places the rest in a temp file and then feeds that to scala:
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p scala
tmp=mktemp
cat "$0" | tail +8 > $tmp
exec scala "$tmp" "$@"
!#
object Main extends App {
import scala.sys.process._
val cmd = "ls -l" // Your command
val output = cmd.!! // Captures the output
println(output)
println("Hello World: " + (args mkString ", "))
}
For Scala, using Ammonite for scripts would be a better choice, see: https://github.com/lihaoyi/Ammonite/pull/686
#! /usr/bin/env nix-shell
#! nix-shell -i amm -p ammonite-repl
!#
import scala.sys.process._
val cmd = "ls -l" // Your command
val output = cmd.!! // Captures the output
println(output)
println("Hello World")
NodeJS has the same problem, execution fails with a SyntaxError on the following:
#! /usr/bin/env nix-shell
#! nix-shell -i node -p nodejs
console.log('ok');
Looking through the logic in Nix source: https://github.com/NixOS/nix/blob/a0ef21262f4d5652bfb65cfacaec01d89c475a93/src/nix-build/nix-build.cc#L109-L128 It seems it's possible to work around the problem by commenting out the next shebang line in whichever way the language requires (Node has special-case rules for the first line), and to write the following, which works:
#! /usr/bin/env nix-shell
/*
#! nix-shell -i node -p nodejs
*/
console.log('ok');
I marked this as stale due to inactivity. → More info
I closed this issue due to inactivity. → More info
http://nixos.org/nix/manual/#ssec-nix-shell-shebang:
This hack falls down when targeting real interpreters in which both (1) multiple shebang lines aren't admitted and (2) in which
#
s don't indicate the start of a comment. This is true of at least Lua:One workaround might be to remove shebang lines before passing off scripts to their target interpreters, writing out modified scripts to temporary files. Overriding the zeroth argument with
exec -a
(as in the existing Perl "Überhack") should keep the environment fairly sane, and I don't see any good reasons for other interpreters to processnix-shell
directives. Before I try working up a patch, thoughts?