Skip to content

babashka: Add wrapper #241119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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=";
};

Expand All @@ -27,6 +28,8 @@ buildGraalvmNativeImage rec {
"--enable-preview"
];

doInstallCheck = true;

installCheckPhase = ''
$out/bin/bb --version | grep '${version}'
$out/bin/bb '(+ 1 2)' | grep '3'
Expand Down Expand Up @@ -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:

- 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
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
'';
homepage = "https://github.com/babashka/babashka";
changelog = "https://github.com/babashka/babashka/blob/v${version}/CHANGELOG.md";
Expand Down
35 changes: 35 additions & 0 deletions pkgs/development/interpreters/babashka/wrapped.nix
Original file line number Diff line number Diff line change
@@ -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;
})
2 changes: 2 additions & 0 deletions pkgs/development/interpreters/clojure/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
Expand Down
4 changes: 3 additions & 1 deletion pkgs/development/interpreters/clojure/obb.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{ lib
, stdenv
, fetchurl
, babashka
, cacert
, clojure
Expand Down Expand Up @@ -79,5 +78,8 @@ stdenv.mkDerivation rec {
willcohen
];
platforms = platforms.darwin;

# https://hydra.nixos.org/job/nixpkgs/trunk/obb.aarch64-darwin/all
broken = true;
};
}
7 changes: 3 additions & 4 deletions pkgs/development/tools/bbin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
, stdenvNoCC
, fetchFromGitHub
, makeWrapper
, babashka
, graalvm17-ce
, babashka-unwrapped
}:

stdenvNoCC.mkDerivation rec {
Expand All @@ -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
'';
Expand All @@ -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 changes: 1 addition & 2 deletions pkgs/development/tools/neil/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
, fetchFromGitHub
, makeWrapper
, babashka
, jdk
}:

stdenv.mkDerivation rec {
Expand All @@ -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; {
Expand Down
3 changes: 2 additions & 1 deletion pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down