Fork me on GitHub
#babashka
<
2021-05-28
>
Buidler00:05:28

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")))

borkdude07:05:20

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

borkdude07:05:51

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

verma00:05:10

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.

borkdude06:05:39

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

jeroenvandijk07:05:23

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

borkdude07:05:53

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

👍 1
kokada16:05:15

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

kokada16:05:19

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

kokada16:05:19

(Well, anywhere that have curl installed at least)

verma20:05:59

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

bruno.bonacci09:05:05

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
babashka 2
littleli11:05:01

@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?

borkdude11:05:02

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

littleli11:05:24

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

borkdude11:05:13

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

littleli11:05:34

don't do it just yet

littleli11:05:10

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

littleli11:05:41

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

borkdude11:05:28

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

littleli11:05:53

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

borkdude11:05:10

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

littleli11:05:14

yeah, as a default above would be great

littleli11:05:08

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

littleli11:05:40

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

borkdude11:05:25

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

borkdude11:05:42

you must use the aarch64 binary there I believe?

littleli11:05:56

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

borkdude11:05:13

the install script does that automatically

borkdude11:05:22

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

littleli11:05:10

this won't work 😞

littleli11:05:47

~$ ./bb
Bad system call

littleli11:05:55

(with static linking)

littleli11:05:09

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

borkdude11:05:44

this might be the glibc stuff

littleli11:05:56

yeah, on Android there is no glibc

borkdude11:05:20

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

littleli11:05:23

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

littleli11:05:17

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

littleli11:05:34

so yeah... not everything is shinny and beatiful 🙂

lispyclouds11:05:53

> 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

lispyclouds11:05:19

very very off the top of my head, very possible none of it works 😅

borkdude11:05:49

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

lispyclouds11:05:24

good weekend project for me it seems

borkdude11:05:37

or just wait for Graal to support it ;)

1
borkdude11:05:20

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.

borkdude11:05:29

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

lispyclouds11:05:48

one can hope!

borkdude12:05:24

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

Tomas Brejla13:05:23

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

Tomas Brejla13:05:10

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.

littleli13:05:37

@U01LFP3LA6P ok, it works... thank you fellow citizen! 🙂

Tomas Brejla13:05:04

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 @U0522TWDA and it works flawlessly. It even opens a chrome browser and navigates to the server page.

😻 1
littleli13:05:25

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

truestory 1
kokada13:05:56

@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

kokada13:05:24

@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

littleli13:05:11

@UFDRD93RR I believe you, it makes sense.

kokada13:05:49

> 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

kokada13:05:38

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

littleli13:05:11

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

littleli13:05:30

btw it even works on Windows if I install Busybox on it 😄

littleli13:05:10

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

littleli13:05:23

(thank you busybox!)

kokada13:05:09

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)

kokada13:05:50

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

borkdude14:05:31

well mktemp makes a temporary file rather than a directory right

borkdude14:05:42

ah -d creates a dir? perfect

borkdude14:05:40

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

borkdude14:05:09

This will be the most solid install script ever ;)

littleli14:05:18

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

borkdude14:05:35

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

littleli15:05:01

is there a PR?

kokada15:05:14

Yeah, for Linux

borkdude15:05:47

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

littleli15:05:45

This script is btw a remarkable example of why bb exists in the first place 😄

littleli15:05:04

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

littleli15:05:37

it looks good to me. nice bash skills.

littleli15:05:02

it works in Termux, backup of old version done 👏

kokada15:05:13

> 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
kokada18:05:23

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
kokada18:05:56

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

kokada21:05:00

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]().

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.

kokada21:05:07

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

borkdude21:05:00

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

borkdude21:05:12

Maybe under "recipes"

borkdude21:05:57

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

borkdude21:05:10

btw, I opened the wiki now

lukasz15:05:25

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?

borkdude15:05:49

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

lukasz15:05:01

Let me check, I think I tried that before

borkdude15:05:24

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

lukasz15:05:06

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

borkdude15:05:35

it seems to work here:

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

borkdude15:05:39

lots of info printed

lukasz15:05:04

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

borkdude15:05:38

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

lukasz15:05:01

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

lukasz15:05:56

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

lukasz15:05:01

beauty of babashka

borkdude15:05:14

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

kokada20:05:08

TIL, this works:

$ curl  -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