query
On this page

writeBabashka

pkgs.writers.writeBabashka

Functor
Docs pulled from | This Revision | 10 minutes ago


writeBabashka takes a name, an attrset with babashka interpreter and linting check (both optional) and some babashka source code and returns an executable.

pkgs.babashka-unwrapped is used as default interpreter for small closure size. If dependencies needed, use pkgs.babashka instead. Pass empty string to check to disable the default clj-kondo linting.

Examples

pkgs.writers.writeBabashka with empty arguments

writeBabashka "example" { } ''
  (println "hello world")
''

pkgs.writers.writeBabashka with arguments

writeBabashka "example"
{
  makeWrapperArgs = [
    "--prefix" "PATH" ":" "${lib.makeBinPath [ pkgs.hello ]}"
  ];
}
''
  (require '[babashka.tasks :as tasks])
  (tasks/shell "hello" "-g" "Hello babashka!")
''

Babashka needs Java for fetching dependencies. Wrapped babashka contains jdk, pass wrapped version pkgs.babashka to babashka if dependencies are required.

For example:

writeBabashka "example"
{
  babashka = pkgs.babashka;
}
''
  (require '[babashka.deps :as deps])
  (deps/add-deps '{:deps {medley/medley {:mvn/version "1.3.0"}}})
  (require '[medley.core :as m])
  (prn (m/index-by :id [{:id 1} {:id 2}]))
''

Disable clj-kondo linting:

writeBabashka "example"
{
  check = "";
}
''
  (println "hello world")
''

Noogle detected

This is a Functor

Learn about functors

Implementation

The following is the current implementation of this function.

writeBabashka =
    name:
    {
      makeWrapperArgs ? [ ],
      babashka ? pkgs.babashka-unwrapped,
      check ? "${lib.getExe pkgs.clj-kondo} --lint",
      ...
    }@args:
    makeScriptWriter (
      (builtins.removeAttrs args [
        "babashka"
      ])
      // {
        interpreter = "${lib.getExe babashka}";
      }
    ) name;