babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
noprompt 2020-12-15T00:31:08.286200Z

I need to wrap up what I’ve been working on with meander first before a step over to this.

noprompt 2020-12-15T00:31:50.286300Z

But I’m familiar with the goal of the code and feel confident.

onetom 2020-12-15T04:05:15.289200Z

Is there anyone here using babashka under macOS, but via Nix? In a recent London Clojure online meetup it was mentioned that some ppl are using the JAR distribution of Babashka with Nix somehow. I would be curious what does it mean. (I would really like to integrate Babashka into our projects, but for that I would need a cross-platform solution to install it via Nix.)

borkdude 2020-12-15T08:00:34.290800Z

@onetom There is a nixOS thread here: https://github.com/NixOS/nixpkgs/pull/105815#issuecomment-738687147

πŸ‘ 1
borkdude 2020-12-15T08:01:44.291700Z

What I meant was that the uberjar is built for building the nixOS package, at least, that's why I distribute it because someone had asked me to do this.

2020-12-15T09:40:13.292400Z

A really noob question: how do you transform in string int o an array of bytes in Babahska?

borkdude 2020-12-15T09:44:09.292600Z

(.getBytes "foo")

2020-12-15T09:47:42.292900Z

No need of the standard chars sets?

borkdude 2020-12-15T09:57:05.293400Z

@neo2551 This also works:

$ bb -e '(.getBytes "foo" "UTF-8")'

2020-12-15T09:57:23.293700Z

wow πŸ™‚ Is this supported in Clojure overall?

borkdude 2020-12-15T09:59:18.293900Z

yes

borkdude 2020-12-15T09:59:25.294100Z

it's just the Java API

2020-12-15T10:00:17.294600Z

Wow πŸ™‚ So great!

2020-12-15T10:00:32.294900Z

why does one need the standardcharts set then?

borkdude 2020-12-15T10:04:14.295500Z

I think the Java folks like IDE assistance by using the enums

2020-12-15T10:38:20.295900Z

Haha ok!! Thanks!

helios 2020-12-15T12:03:05.296100Z

@borkdude https://twitter.com/JakeWharton/status/1334177665356587008 <-- good quote for babashka? πŸ˜„

borkdude 2020-12-15T12:06:52.296400Z

@helios thanks :)

kwrooijen 2020-12-15T13:10:09.296700Z

https://github.com/clj-commons/clj-ssh Maybe interesting for BB? Or at least as a pod?

borkdude 2020-12-15T13:11:05.297700Z

@kevin.van.rooijen there is https://github.com/epiccastle/spire. It doesn't yet have a pod interface but it might have one if @retrogradeorbit is picking work back up. He's going through a busy period right now.

borkdude 2020-12-15T13:11:45.298200Z

Usually shelling out works too if it's one-shot invocations

borkdude 2020-12-15T13:12:24.298400Z

But potentially interesting, thanks

kwrooijen 2020-12-15T13:13:14.298800Z

Yeah I was thinking of just using bb's shell interface

borkdude 2020-12-15T13:13:41.299300Z

@kevin.van.rooijen bb recently added babashka.process which is more suitable for longer running programs. Depends on your usage.

borkdude 2020-12-15T13:16:02.299800Z

@kevin.van.rooijen e.g. this is how you can launch an interactive ssh session:

$ bb -e '@(babashka.process/process ["ssh" "borkdude@..."] {:inherit true})'

kwrooijen 2020-12-15T13:16:20.300Z

Very cool!

kwrooijen 2020-12-15T13:16:54.300300Z

That might really come in handy if I need to script multiple commands

borkdude 2020-12-15T13:18:03.300600Z

$ bb -e '(:out @(babashka.process/process ["ssh" "borkdude@..."] {:out :string :in "ls"}))' "Linux ... #1 SMP Fri May 8 15:27:51 UTC 2020 x86_64\n\nThe programs included with the Debian GNU/Linux system are free software;\nthe exact distribution terms for each program are described in the\nindividual files in /usr/share/doc/*/copyright.\n\nDebian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent\npermitted by applicable law.\nNo mail.\nadvent-of-cljc.git\nbalcony\nbalcony.clj\nbalcony.cljs\nbalcony.cljs~\nbalcony-hs\nbalcony.js\nbb\nbb.zip\nbin..."

borkdude 2020-12-15T13:19:22.301300Z

I'm sure ssh also supports passing the command directly, so you can use all of this for scripting using the utilities we already have on our systems

borkdude 2020-12-15T13:19:35.301600Z

Clojure-as-bash FTW

🦜 1
2020-12-15T13:35:29.301800Z

I would you interact with it haha?

kwrooijen 2020-12-15T13:39:23.302100Z

Amazing

borkdude 2020-12-15T13:48:31.302200Z

Is this a question?

Crispin 2020-12-15T13:53:56.302400Z

I will be resuming work on it next year.

Crispin 2020-12-15T13:54:42.302600Z

I tested clj-ssh when I was first building spire but found it to be incomplete. The ssh inside spire used clj-ssh as a starting point but fixed the broken parts and added some features.

Crispin 2020-12-15T13:59:17.302800Z

Things that I had trouble getting working were things like recursive copying (it may work for you but I had troubles) and I added stuff like ssh-agent authentication support so the ssh client can access your keychain, and authentication forwarding so you can shell onwards to other hosts using your local ssh agent keys without copying.

Crispin 2020-12-15T13:59:32.303Z

but clj-ssh should be usable for simple usage.

2020-12-15T14:34:17.303700Z

Sorry, I wondered how you would interact with it.

borkdude 2020-12-15T14:45:05.303900Z

Like any process, either manually or or writing and reading from the in/outputstreams. See babashka.process docs

victorb 2020-12-15T15:19:35.304800Z

not sure if I'm missing something/not finding the right docs so here goes nothing: is it possible to turn a babashka script into a single binary ala what graalvm does?

borkdude 2020-12-15T15:22:02.305500Z

@victorbjelkholm429 babashka doesn't really support this. the closest you would get to this is creating an uberjar or uberscript which you can invoke with bb itself.

victorb 2020-12-15T15:22:38.306Z

@borkdude that's unfortunate, but understandable. Thanks!

borkdude 2020-12-15T15:23:23.306800Z

@victorbjelkholm429 there is this project: https://github.com/MnRA/nativity which converts your script into a binary using GraalVM. How it works: it has a deps.edn with all the libs from bb and from then on its just a normal GraalVM native project

πŸ‘ 2
borkdude 2020-12-15T15:23:32.307200Z

it's a bit out of date maybe

dharrigan 2020-12-15T15:23:49.307900Z

It would be pretty darn cool if babashka could compile scripts to binaries πŸ™‚

victorb 2020-12-15T15:23:53.308Z

I see, interesting, I'll take a look, might be Good Enough(TM). Cheers

borkdude 2020-12-15T15:40:12.309100Z

@dharrigan that would require something built-in like nativity and something which would download GraalVM and then do compile. but not every script that you can run with babashka can run with graalvm, since babashka supports eval and graalvm doesn't =). So even if I would write this integration, I can't guarantee that the end product works

dharrigan 2020-12-15T15:40:43.309400Z

yeah, true true πŸ™‚ Just being fanciful πŸ™‚

borkdude 2020-12-15T15:41:14.309900Z

if there's a tool which can package bb along with a script inside some container like thing, then that could work. but I don't see the added value really

borkdude 2020-12-15T15:41:29.310200Z

maybe upx supports something like this?

borkdude 2020-12-15T15:43:37.310600Z

you can build docker images with bb + script very easily btw

borkdude 2020-12-15T15:50:13.311Z

maybe something like flatpack or the ubuntu snap thing can also work

dharrigan 2020-12-15T15:51:49.311500Z

indeed. but, tbh, as you say, a uberjar works just as well and is portable too

2020-12-15T17:20:27.312100Z

Just as a curiosity, could babashka compiles ClojureScript?

isak 2020-12-15T17:32:08.313900Z

For production builds, compiling ClojureScript requires running some Java (Closure), and babashka "just" has a Clojure intepreter, so I think no, unless you compiled a custom version of babashka that included those java libraries. @neo2551

borkdude 2020-12-15T17:54:08.314400Z

@neo2551 Babashka itself doesn't, but the Clojure interpreter powering it, sci, does work with CLJS

borkdude 2020-12-15T18:46:29.314800Z

So you could build a babashka-js using NodeJS probably

borkdude 2020-12-15T18:46:45.315100Z

The new Deno stuff lets you compile to a native binary I read recently

2020-12-15T19:10:35.316100Z

You could also build with nexe?

2020-12-15T19:10:49.316600Z

Basically shipping chrome xD

borkdude 2020-12-15T19:11:59.318100Z

Here is a sci cljs repl: https://babashka.org/xterm-sci/

2020-12-15T19:12:00.318200Z

My idea was more to compile (simple not advanced) ClojureScript project, so that we could show a light version of CLJS.

borkdude 2020-12-15T19:12:23.318700Z

This is advanced compiled btw

2020-12-15T19:15:28.323600Z

Hum, maybe I am lacking the correct vocabulary. One of the difficult part for starting with ClojureScript is the many tools required before getting started [npm, Clojure, Java and all]. What if we could just download babashka (or a version of it) with some deps (like react) and people could start writing a web app? Then, if they want to make advanced compilation, they would need all the shebang, but just for the repl+live-reloading, I wonder if it could be achieved with β€œjust” babashka.

2020-12-15T19:15:34.323900Z

Or if that even make sense.

2020-12-15T19:16:36.325400Z

With org-http-kit you can now create simple backends, which is great and shows the power of BB and Clojure. It would be interesting if we could have the same story with ClojureScript.

2020-12-15T19:17:01.325800Z

Just an idea.

borkdude 2020-12-15T19:17:02.325900Z

yes, that is possible

borkdude 2020-12-15T19:17:33.326200Z

feel free to experiment :)

2020-12-15T19:18:36.327100Z

Haha. That would be interesting.

borkdude 2020-12-15T20:49:25.328100Z

https://twitter.com/borkdude/status/1338905522846769155 πŸŽ‰

πŸ‘ 4
πŸŽ‰ 11
lread 2020-12-15T22:18:09.332300Z

Hiya @borkdude, I just noticed that maybe bb/sci does not support auto-resolve current namespace maps?

&gt; bb --repl
Babashka v0.2.5 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=&gt; #::{:a 1 :b 2}
[line 1, col 4] Invalid keyword: .
user=&gt; {:b 2, :a 1}
Note this is not a problem for me. It is just something that I stumbled upon. Happy to raise an issue if you’d like.

borkdude 2020-12-15T22:19:24.332800Z

Aha, that's an edge case I haven't encountered before in real code. Thanks for discovering it! An issue is surely welcome.

lread 2020-12-15T23:04:22.333500Z

will do!

lread 2020-12-15T23:42:25.333800Z

here ya go: https://github.com/borkdude/babashka/issues/684