Fork me on GitHub
#babashka
<
2022-06-14
>
borkdude09:06:42

Added an example of how to call kaocha with babashka CLI https://github.com/babashka/cli#kaocha And now I also made a #babashka-cli channel - anything about that project will be discussed there

🔥 1
Jacob Chvatal10:06:38

Hey! I'm trying to use babashka/process to execute a command that requires sudo. So far, I have this, but I'm not sure how to wait for the root password and avoid terminating immediately...

(defn rebuild [flake]
  (do (p/process
        ["sudo" "nixos-rebuild" "switch"
         "--flake" flake
         "--option" "pure-eval" "no"]
        {:out :inherit})
      nil))
Any tips? Is there a better way to acquire root permissions for the command?

borkdude10:06:09

Use :in :inherit to let the process read input. Also you might want to block for the process until it ends by derefing it: (do @(p/process ...))

Jacob Chvatal10:06:32

ah thank you! definitely want both of those

Jacob Chvatal10:06:13

that works perfectly - thanks!

borkdude10:06:59

@U03KM7AH74L If you are on the newest version you might want to use p/shell here which blocks and also inherits :in automatically and has a nicer syntax:

(p/shell "sudo nixos-rebuild switch ...")

borkdude11:06:54

E.g.:

$ bb -e '(-> (babashka.process/shell {:out :string} "cat") :out)'
1
"1\n"

oddsor11:06:09

Hello! This is probably a lot simpler than I’m thinking, but; I made a little web-server in Babashka and was wondering how I can run an nrepl-server alongside the webserver? In other words, how can I start an nrepl-server in Babashka via code? Or can I maybe use bb nrepl-server and also run a main-method at the same time? :thinking_face:

borkdude11:06:57

@odd.andreas you can maybe use the --init flag which allows you to execute a file prior to the nrepl-server command

👀 1
oddsor12:06:32

Interesting workaround, seems to do the trick! If your script has a main-function I guess you should make another one that just invokes it, or are there other cool tricks for invoking a function too? 😁

borkdude12:06:15

You can invoke a main function with -m foo/bar

borkdude12:06:32

or do you mean as part of --init?

oddsor13:06:31

sorry, was in a meeting! So in this hypothetical scenario I’d have a server.clj script file, with a main-function that launches a web server. If I want to start both an nrepl-server and the webserver, I guess I would ideally want to do something like

bb --init server.clj -m server[/-main] nrepl-server
In the current working example I don’t have a main-function, so the web-server just starts because of the file being initialized 😊

borkdude13:06:03

In this scenario you can use this trick: https://book.babashka.org/#main_file

borkdude13:06:01

well, actually no sorry, that's only when you do bb file.clj

borkdude13:06:26

I think it would be better if we made the starting of the nREPL server programmatically available

1
borkdude13:06:30

feel free to make an issue about this

oddsor13:06:17

Alright, thanks! Being able to start a server programmatically would be neat, but in the short term it seems like my use-case is covered using --init :thumbsup:

oddsor13:06:56

I made an issue to the best of my ability 😊 Thanks! https://github.com/babashka/babashka/issues/1295

dabrazhe20:06:33

What is the right way to create a classpath for uberscript? Trying to create a container with bb. When I use babashka/babashka:latest image the following lines give an error.

RUN  clojure -Sdeps '{:mvn/local-repo "./.m2/repository"}' -Spath > cp
RUN ./bb -cp $(cat cp) -m lambda.core --uberscript core.clj

----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  java.lang.IllegalArgumentException: host is null: http:///2018-06-01/runtime/invocation/next
Location: /var/task/src/lambda/impl/runtime.clj:43:11

borkdude20:06:23

@U96LS78UV Just run bb uberscript and put your deps in bb.edn

borkdude20:06:36

The invocation nowadays is:

bb uberscript foo.clj -m lambda.core

dabrazhe20:06:57

Thank you will give it a try.

borkdude20:06:55

An uberjar can also be an option, if uberscript doesn't work:

bb uberjar foo.jar -m lambda.core
bb foo.jar 

dabrazhe21:06:52

Getting this puzzling message with uberscript:

[babashka] Ignoring expression while assembling uberscript: (ns user (:require [lambda.core :as nil])) near 1:35

borkdude21:06:57

Probably safe to ignore

borkdude21:06:09

The :as nil is weird tho