babashka: Add wrapper

To resolve dependecies in `bb.edn` files, Babashka depends on some
Clojure files and Java, see:
https://github.com/borkdude/deps.clj/tree/master#deps_clj_tools_dir

The wrapper also adds rlwrap, as recommended in the Babashka
documentation:
https://book.babashka.org/#_repl

I'm also formatting the file with nixpkgs-fmt
This commit is contained in:
José Luis Lafuente 2023-07-02 16:20:18 +02:00
parent 645ff62e09
commit 4a22edafaa
No known key found for this signature in database
GPG Key ID: 8A3455EBE455489A
7 changed files with 63 additions and 22 deletions

@ -3,14 +3,15 @@
, graalvmCEPackages
, removeReferencesTo
, fetchurl
, writeScript }:
, writeScript
}:
buildGraalvmNativeImage rec {
pname = "babashka";
pname = "babashka-unwrapped";
version = "1.3.181";
src = fetchurl {
url = "https://github.com/babashka/${pname}/releases/download/v${version}/${pname}-${version}-standalone.jar";
url = "https://github.com/babashka/babashka/releases/download/v${version}/babashka-${version}-standalone.jar";
sha256 = "sha256-NzchlHRxOCSyUf9U0Jv8h4bgKd2Jwp+LmxIfeV8+8+M=";
};
@ -27,6 +28,8 @@ buildGraalvmNativeImage rec {
"--enable-preview"
];
doInstallCheck = true;
installCheckPhase = ''
$out/bin/bb --version | grep '${version}'
$out/bin/bb '(+ 1 2)' | grep '3'
@ -68,18 +71,18 @@ buildGraalvmNativeImage rec {
too simple to be worth writing a clj/s script for. Babashka really
seems to hit the sweet spot for those cases.
Goals:
Goals:
- Low latency Clojure scripting alternative to JVM Clojure.
- Easy installation: grab the self-contained binary and run. No JVM needed.
- Familiarity and portability:
- Scripts should be compatible with JVM Clojure as much as possible
- Scripts should be platform-independent as much as possible. Babashka
offers support for linux, macOS and Windows.
- Allow interop with commonly used classes like java.io.File and System
- Multi-threading support (pmap, future, core.async)
- Batteries included (tools.cli, cheshire, ...)
- Library support via popular tools like the clojure CLI
- Low latency Clojure scripting alternative to JVM Clojure.
- Easy installation: grab the self-contained binary and run. No JVM needed.
- Familiarity and portability:
- Scripts should be compatible with JVM Clojure as much as possible
- Scripts should be platform-independent as much as possible. Babashka
offers support for linux, macOS and Windows.
- Allow interop with commonly used classes like java.io.File and System
- Multi-threading support (pmap, future, core.async)
- Batteries included (tools.cli, cheshire, ...)
- Library support via popular tools like the clojure CLI
'';
homepage = "https://github.com/babashka/babashka";
changelog = "https://github.com/babashka/babashka/blob/v${version}/CHANGELOG.md";

@ -0,0 +1,35 @@
{ stdenv
, babashka-unwrapped
, clojure
, makeWrapper
, rlwrap
, jdkBabashka ? clojure.jdk
}:
stdenv.mkDerivation (finalAttrs: {
pname = "babashka";
inherit (babashka-unwrapped) version meta doInstallCheck installCheckPhase;
dontUnpack = true;
dontBuild = true;
nativeBuildInputs = [ makeWrapper ];
installPhase =
let unwrapped-bin = "${babashka-unwrapped}/bin/bb"; in
''
mkdir -p $out/clojure_tools
ln -s -t $out/clojure_tools ${clojure}/*.edn
ln -s -t $out/clojure_tools ${clojure}/libexec/*
makeWrapper "${babashka-unwrapped}/bin/bb" "$out/bin/bb" \
--inherit-argv0 \
--set-default DEPS_CLJ_TOOLS_DIR $out/clojure_tools \
--set-default JAVA_HOME ${jdkBabashka}
substituteInPlace $out/bin/bb \
--replace '"${unwrapped-bin}"' '"${rlwrap}/bin/rlwrap" "${unwrapped-bin}"'
'';
passthru.unwrapped = babashka-unwrapped;
})

@ -71,6 +71,8 @@ stdenv.mkDerivation (finalAttrs: {
update-source-version clojure "$latest_version"
'';
passthru.jdk = jdk;
meta = with lib; {
description = "A Lisp dialect for the JVM";
homepage = "https://clojure.org/";

@ -1,6 +1,5 @@
{ lib
, stdenv
, fetchurl
, babashka
, cacert
, clojure
@ -79,5 +78,8 @@ stdenv.mkDerivation rec {
willcohen
];
platforms = platforms.darwin;
# https://hydra.nixos.org/job/nixpkgs/trunk/obb.aarch64-darwin/all
broken = true;
};
}

@ -2,8 +2,7 @@
, stdenvNoCC
, fetchFromGitHub
, makeWrapper
, babashka
, graalvm17-ce
, babashka-unwrapped
}:
stdenvNoCC.mkDerivation rec {
@ -29,7 +28,7 @@ stdenvNoCC.mkDerivation rec {
mkdir -p $out/share
cp -r docs $out/share/docs
wrapProgram $out/bin/bbin \
--prefix PATH : "${lib.makeBinPath [ babashka babashka.graalvmDrv ]}"
--prefix PATH : "${lib.makeBinPath [ babashka-unwrapped babashka-unwrapped.graalvmDrv ]}"
runHook postInstall
'';
@ -38,7 +37,7 @@ stdenvNoCC.mkDerivation rec {
homepage = "https://github.com/babashka/bbin";
description = "Install any Babashka script or project with one command";
license = licenses.mit;
inherit (babashka.meta) platforms;
inherit (babashka-unwrapped.meta) platforms;
maintainers = with maintainers; [ sohalt ];
};
}

@ -3,7 +3,6 @@
, fetchFromGitHub
, makeWrapper
, babashka
, jdk
}:
stdenv.mkDerivation rec {
@ -24,7 +23,7 @@ stdenv.mkDerivation rec {
installPhase = ''
install -D neil $out/bin/neil
wrapProgram $out/bin/neil \
--prefix PATH : "${lib.makeBinPath [ babashka jdk ]}"
--prefix PATH : "${lib.makeBinPath [ babashka ]}"
'';
meta = with lib; {

@ -17108,7 +17108,8 @@ with pkgs;
angelscript = callPackage ../development/interpreters/angelscript { };
babashka = callPackage ../development/interpreters/clojure/babashka.nix { };
babashka-unwrapped = callPackage ../development/interpreters/babashka { };
babashka = callPackage ../development/interpreters/babashka/wrapped.nix { };
# BQN interpreters and compilers