babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
2021-05-28T00:14:28.259800Z

Is there a way to get that fs/delete function to work using a relative path? Something like this:

(shell/with-sh-dir root-dir
  (fs/delete (fs/path "foo")))

borkdude 2021-05-28T07:24:20.264500Z

clojure.java.shell and babashka.fs are two different libraries, with-sh-dir doesn't affect fs/delete

borkdude 2021-05-28T07:31:51.264700Z

if you want to do this, you'll have to use (fs/delete (fs/path root-dir "foo"))

verma 2021-05-28T00:35:10.262800Z

Is there a way for me to create a single exe out of babashka + my scripts (perhaps cli-matic based) .. I want to do this because I want to distribute a tool to some of the engineers to execute certain commands against our production cluster (with a single file its convenient, just put it in path). They have permissions and everything, the scripts just simplify certain flows. I found this: https://github.com/MnRA/nativity which I will give it a try. I was wondering if there's some in-built way of doing so.

2021-05-28T07:41:23.265100Z

For a single file uberscript might be useful, right? https://book.babashka.org/#_uberscript

borkdude 2021-05-28T07:41:53.265500Z

yes, but then you still need babashka to execute it. I think @verma wants a single executable with all sources included

πŸ‘ 1
kokada 2021-05-28T16:20:43.294500Z

Another approach: https://gist.github.com/thiagokokada/115b2588ff65a48d54b8832488801c92

πŸ‘ 1
kokada 2021-05-28T16:21:15.294700Z

This gist downloads Babashka to $HOME/.bb, if it doesn't exist, and re-exec the file as a Babashka script

kokada 2021-05-28T16:22:19.295Z

Combine this with uberscript and you should have a Babashka script that runs anywhere

kokada 2021-05-28T16:25:19.295200Z

(Well, anywhere that have curl installed at least)

verma 2021-05-28T20:25:59.295900Z

Very nice, thanks for all the insights, much appreciated. I will take a look at these sources and see what I come up with πŸ™‚

borkdude 2021-05-28T06:34:39.264100Z

You could convert your script to a GraalVM project but I think just letting them download babashka is the easiest

skuro 2021-05-28T06:55:58.264300Z

worked like a charm, thanks!

2021-05-28T09:32:05.267200Z

Hi all, @borkdude will be talking about Babashka tasks at the London Clojurians meetup in July https://www.meetup.com/London-Clojurians/events/278466747/

πŸ‘ 3
2
littleli 2021-05-28T11:24:01.269800Z

@borkdude install script failed on one of my systems because of the default_download_dir="/tmp" as on the system there is no write access to /tmp I was wondering if you could do 1) use TMPDIR environment variable (as described https://en.wikipedia.org/wiki/TMPDIR) 2) allow option to specify location for temporary files 3) both 1 and 2. Should I open ticket for it?

borkdude 2021-05-28T11:26:02.270200Z

@ales.najmann the script has a --download-dir option

littleli 2021-05-28T11:26:24.270600Z

oh, you're right... my bad! good

borkdude 2021-05-28T11:27:13.271200Z

but we could actually change the default to $TMPDIR, that's probably better, I will do that now

littleli 2021-05-28T11:27:34.271400Z

don't do it just yet

littleli 2021-05-28T11:28:10.271600Z

there is issue that some of distros actualy don't set it up... so it's one of those cases wher POSIX tells something, but systems don't respect it generally

littleli 2021-05-28T11:28:41.271800Z

I think it's ok to not have a support for this... as I can always say: --download-dir=$TMPDIR from the outside

borkdude 2021-05-28T11:29:28.272Z

yeah, we can choose ${TMPDIR:-/tmp}

littleli 2021-05-28T11:29:53.272200Z

Debian don't set TMPDIR it seems, also Arch don't have it

borkdude 2021-05-28T11:30:10.272400Z

yes, so it defaults to /tmp/ is TMPDIR is not there

littleli 2021-05-28T11:30:14.272600Z

yeah, as a default above would be great

littleli 2021-05-28T11:31:08.272800Z

btw if you're interested what I wanted to try... I wanted to install bb to Termux on Android

littleli 2021-05-28T11:31:40.273200Z

Did you have a chance to try it in this environment?

borkdude 2021-05-28T11:33:25.273500Z

applied the change. no, I haven't tried it

borkdude 2021-05-28T11:33:42.273700Z

you must use the aarch64 binary there I believe?

littleli 2021-05-28T11:33:56.273900Z

Ok. I'll try and let you know if it works πŸ™‚ yes, aarch64 binary has to be used.

borkdude 2021-05-28T11:34:13.274100Z

the install script does that automatically

borkdude 2021-05-28T11:34:22.274300Z

if it doesn't work, try the --static option

littleli 2021-05-28T11:38:02.274500Z

oh oh

littleli 2021-05-28T11:38:10.274700Z

this won't work 😞

littleli 2021-05-28T11:38:47.274900Z

~$ ./bb
Bad system call

littleli 2021-05-28T11:38:55.275100Z

(with static linking)

littleli 2021-05-28T11:39:09.275300Z

With normal binary, it doesn't see it as executable

borkdude 2021-05-28T11:39:44.275500Z

this might be the glibc stuff

littleli 2021-05-28T11:39:56.275700Z

yeah, on Android there is no glibc

borkdude 2021-05-28T11:40:20.275900Z

if GraalVM supported linking with musl on aarch64 then this would be no problem, but it currently doesn't cc @thiagokokada @rahul080327

littleli 2021-05-28T11:40:23.276100Z

they have Bionic if I remember correctly, which is something similar to musl

borkdude 2021-05-28T11:40:36.276300Z

you could read in this topic: https://github.com/babashka/babashka/issues/241#issuecomment-804721420

littleli 2021-05-28T11:46:51.276700Z

πŸ‘

littleli 2021-05-28T11:47:17.276900Z

at least the one thing with TMPDIR comes out of it. That already pleases my ❀️

littleli 2021-05-28T11:49:02.277100Z

This sums the differences pretty well: https://wiki.termux.com/wiki/Differences_from_Linux

littleli 2021-05-28T11:49:34.277300Z

so yeah... not everything is shinny and beatiful πŸ™‚

lispyclouds 2021-05-28T11:52:53.277500Z

> if GraalVM supported linking with musl on aarch64 maybe if its possible to get a graal to just emit the object file for aarch64, not do the full link, MAYBE we could figure out the rest of the linkage with musl.a for aarch64 instead of letting graal do the link. in theory this should work

lispyclouds 2021-05-28T11:53:19.277700Z

very very off the top of my head, very possible none of it works πŸ˜…

borkdude 2021-05-28T11:54:49.277900Z

you can emit more info with --native-image-info and see all the c/c++ stuff it does

lispyclouds 2021-05-28T11:55:24.278100Z

good weekend project for me it seems

borkdude 2021-05-28T11:55:37.278300Z

or just wait for Graal to support it ;)

1
borkdude 2021-05-28T11:59:20.278600Z

Hmm, I'm seeing a new --target argument:

--target              selects native-image compilation target (in <OS>-<architecture>
                          format). Defaults to host's OS-architecture pair.

borkdude 2021-05-28T11:59:29.278800Z

does this mean it now supports cross-compilation? ;)

lispyclouds 2021-05-28T11:59:48.279Z

one can hope!

borkdude 2021-05-28T12:01:24.279200Z

I don't think so, but I wonder what it's for

Tomas Brejla 2021-05-28T13:03:23.279600Z

@ales.najmann did you manage to run bb in Termux?

Tomas Brejla 2021-05-28T13:05:10.279800Z

if you're getting Bad system call , then first try running termux-chroot command and then execute bb . It might help (it did for me - Android 10.

littleli 2021-05-28T13:20:37.280100Z

@brdloush ok, it works... thank you fellow citizen! πŸ™‚

Tomas Brejla 2021-05-28T13:24:04.280300Z

No problem. Now tell me what's your plan with bb on termux πŸ˜‰. I have a feeling that having an option to execute bb on your android phone/tablet (via termux) might be opening a huge amount of new possibilities. But I haven't discovered them yet πŸ˜„. Tried running http server from @holyjak and it works flawlessly. It even opens a chrome browser and navigates to the server page.

😻 1
littleli 2021-05-28T13:26:25.280500Z

well, well. I'm still just playing around with Clojure and Babashka is just another option to explore Lisp world.

1
kokada 2021-05-28T13:30:56.280800Z

@borkdude About the TMPDIR issue. Maybe it is better to create the temporary directory using mktemp instead. At least on Linux, it does the correct thing. From the documentation:

if DIR is not specified, use $TMPDIR if set, else /tmp

kokada 2021-05-28T13:33:24.281Z

@ales.najmann I don't think this is the issue of linking with glibc, I think this is a SELinux issue https://github.com/MasterDevX/Termux-Java/issues/3#issuecomment-548653884 To fix it, install proot, run proot -0 and try to run ./bb again

littleli 2021-05-28T13:34:11.281300Z

@thiagokokada I believe you, it makes sense.

kokada 2021-05-28T13:34:49.281500Z

> Maybe it is better to create the temporary directory usingΒ mktempΒ instead. Looking at the macOS manpage it also seems to do the correct thing there: https://ss64.com/osx/mktemp.html > mktemp will generate a template string based on the prefix and the CSDARWIN_USER_TEMP_DIR configuration variable if available. Fallback locations if CSDARWIN_USER_TEMP_DIR is not available are TMPDIR and /tmp. I can open a PR if you want

kokada 2021-05-28T13:44:38.281900Z

Can you test it @ales.najmann? I remember testing it in the past, not sure if this is still the fix. But maybe if this is really "the fix" for now, we could document this somewhere

littleli 2021-05-28T13:46:11.282200Z

mktemp seems to be available on Termux, so it can be used I believe

littleli 2021-05-28T13:46:30.282400Z

btw it even works on Windows if I install Busybox on it πŸ˜„

littleli 2021-05-28T13:47:10.282600Z

but I just destroyed quite a lot of shims in my scoop environment 😞

littleli 2021-05-28T13:47:23.282800Z

(thank you busybox!)

kokada 2021-05-28T13:52:09.283Z

TIL, surprised to discover that mktemp is not POSIX, but seems to be supported everywhere we care: https://stackoverflow.com/a/2792789 (Also, coreutils, busybox and toybox includes it, so pretty much any Linux distribution will have it too)

kokada 2021-05-28T13:52:50.283500Z

Just need to take care about the flags, but -d flag seems to be supported anywhere (the flag we care for this case)

borkdude 2021-05-28T14:23:49.283800Z

PR welcome

borkdude 2021-05-28T14:24:31.284Z

well mktemp makes a temporary file rather than a directory right

borkdude 2021-05-28T14:25:42.284200Z

ah -d creates a dir? perfect

borkdude 2021-05-28T14:26:40.284500Z

perhaps make a fallback to just ${TMPDIR:-/tmp} if mktemp cannot be found

borkdude 2021-05-28T14:29:09.284700Z

This will be the most solid install script ever ;)

littleli 2021-05-28T14:32:18.284900Z

SELinux ready I would say. Babashka can be now installed with curl on nuclear power plan without any concerns πŸ™‚

borkdude 2021-05-28T14:59:35.285200Z

@thiagokokada I assume you tested the script locally.. correct?

littleli 2021-05-28T15:01:01.285900Z

is there a PR?

borkdude 2021-05-28T15:01:14.286300Z

https://github.com/babashka/babashka/pull/870

lukasz 2021-05-28T15:01:25.286900Z

I need to debug some of the http requests I'm making with http-kit.client bundled with babashka - is there a way to pass the `

-Djavax.net.debug=all
flag somehow?

borkdude 2021-05-28T15:01:49.287200Z

@lukaszkorecki you should be able to pass JVM opts as the first args to bb

kokada 2021-05-28T15:02:14.287500Z

Yeah, for Linux

kokada 2021-05-28T15:02:20.287700Z

NixOS

borkdude 2021-05-28T15:02:47.288Z

ok, if @ales.najmann gives the OK, I'll merge :)

lukasz 2021-05-28T15:03:01.288300Z

Let me check, I think I tried that before

borkdude 2021-05-28T15:03:24.288700Z

it depends on when programs read this variable whether it's being picked up

littleli 2021-05-28T15:03:45.288800Z

This script is btw a remarkable example of why bb exists in the first place πŸ˜„

lukasz 2021-05-28T15:05:06.289500Z

Ah I see - I included it after args passed to bb 🀦

borkdude 2021-05-28T15:05:35.290Z

it seems to work here:

$ bb -Djavax.net.debug=all -e '(do @(org.httpkit.client/get "<https://clojure.org>") nil)'

borkdude 2021-05-28T15:05:39.290200Z

lots of info printed

lukasz 2021-05-28T15:05:47.290500Z

Yep!

littleli 2021-05-28T15:06:04.290600Z

wow, there is even a fix for a bug with move from bb to bb.old right?

lukasz 2021-05-28T15:07:04.291300Z

Ah, bummer - the option works, but it's not what I need - this only prints SSL/TLS diagnostic info, I just need to debug the actual request being sent

littleli 2021-05-28T15:07:37.291700Z

it looks good to me. nice bash skills.

borkdude 2021-05-28T15:07:38.291900Z

@lukaszkorecki does httpkit document that this option should work for debugging its request?

lukasz 2021-05-28T15:08:01.292100Z

I assume this isn't included in bb: https://clojars.org/http-kit.debug

borkdude 2021-05-28T15:08:14.292400Z

merged.

lukasz 2021-05-28T15:08:56.293Z

@borkdude nothing in http-kit docs. It's ok, I can switch to regular Clojure to verify what's going on

lukasz 2021-05-28T15:09:01.293200Z

beauty of babashka

borkdude 2021-05-28T15:09:14.293500Z

yeah, I recommend doing that. I wasn't aware of http-kit.debug

littleli 2021-05-28T15:10:02.293600Z

it works in Termux, backup of old version done πŸ‘

borkdude 2021-05-28T15:10:40.293800Z

nice

kokada 2021-05-28T15:28:13.294100Z

> This script is btw a remarkable example of whyΒ bbΒ exists in the first place Yeah, exactly I have a similar script to bootstrap Babashka automatically in a project of mine. It is three times bigger than the rest of the init code of the project, most by trying to make it "safe"

πŸ‘ 1
kokada 2021-05-28T18:35:23.295500Z

Just a correction: the "Bad system call" issue is related to seccomp enforcement on newer Android versions, not SELinux: https://toybox.landley.narkive.com/v0fQYJw7/android-o-xargs-bad-system-call#post8

1
kokada 2021-05-28T18:41:56.295700Z

And using termux-chroot seems to be better than proot -0 (it is available by installing the same package)

kokada 2021-05-28T20:46:08.297500Z

TIL, this works:

$ curl <https://github.com/babashka/babashka/releases/download/v0.4.3/babashka-0.4.3-linux-aarch64-static.tar.gz> -LO
$ tar xfv babashka-0.4.3-linux-aarch64-static.tar.gz
$ time qemu-aarch64 ./bb -e "(+ 1 2)"
3
qemu-aarch64 ./bb -e "(+ 1 2)" 0.19s user 0.03s system 106% cpu 0.201 total
And it is not even that slow

kokada 2021-05-28T21:14:00.298200Z

Since I can't edit the Wiki to add this, here is a documentation about this part:

# Running Babashka on Android with Termux

You can run the static builds of Babashka on Android inside Termux. However if you're using Android 8.0+, you may have the following error while trying to run them:

`
$ ./bb
Bad system call
`

This happens because of `seccomp` rules enforcement on newer versions of Android, as can be seem on [this link](<https://toybox.landley.narkive.com/v0fQYJw7/android-o-xargs-bad-system-call#post8>).

As a workaround, you can run Babashka inside `proot`, an user-space implementation of `chroot`. To do this, run:

`
$ pkg install proot
$ termux-chroot
$ ./bb
`

Note that only basic functionality was tested and this is completely unsupported.

kokada 2021-05-28T21:19:07.298700Z

@borkdude Do you think it makes sense to add that on the Wiki :thinking_face: ?

borkdude 2021-05-28T21:41:00.299Z

It might be better to add this to http://book.babashka.org?

borkdude 2021-05-28T21:41:12.299200Z

Maybe under "recipes"

borkdude 2021-05-28T21:41:57.299400Z

or yeah, since this is experimental, let's do the wiki. or you can just post it on Github discussions

borkdude 2021-05-28T21:44:10.299600Z

btw, I opened the wiki now

kokada 2021-05-28T22:38:44.302400Z

Done