From 4a22edafaabc5965ac0e1d9883641c65e26ff02c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Lafuente?= Date: Sun, 2 Jul 2023 16:20:18 +0200 Subject: [PATCH] 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 --- .../babashka.nix => babashka/default.nix} | 31 ++++++++-------- .../interpreters/babashka/wrapped.nix | 35 +++++++++++++++++++ .../interpreters/clojure/default.nix | 2 ++ pkgs/development/interpreters/clojure/obb.nix | 4 ++- pkgs/development/tools/bbin/default.nix | 7 ++-- pkgs/development/tools/neil/default.nix | 3 +- pkgs/top-level/all-packages.nix | 3 +- 7 files changed, 63 insertions(+), 22 deletions(-) rename pkgs/development/interpreters/{clojure/babashka.nix => babashka/default.nix} (73%) create mode 100644 pkgs/development/interpreters/babashka/wrapped.nix diff --git a/pkgs/development/interpreters/clojure/babashka.nix b/pkgs/development/interpreters/babashka/default.nix similarity index 73% rename from pkgs/development/interpreters/clojure/babashka.nix rename to pkgs/development/interpreters/babashka/default.nix index cd09b5a76235..68f3bed2080d 100644 --- a/pkgs/development/interpreters/clojure/babashka.nix +++ b/pkgs/development/interpreters/babashka/default.nix @@ -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"; diff --git a/pkgs/development/interpreters/babashka/wrapped.nix b/pkgs/development/interpreters/babashka/wrapped.nix new file mode 100644 index 000000000000..64c4acff066c --- /dev/null +++ b/pkgs/development/interpreters/babashka/wrapped.nix @@ -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; +}) diff --git a/pkgs/development/interpreters/clojure/default.nix b/pkgs/development/interpreters/clojure/default.nix index 3f70c30dc8d3..18984e2b774c 100644 --- a/pkgs/development/interpreters/clojure/default.nix +++ b/pkgs/development/interpreters/clojure/default.nix @@ -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/"; diff --git a/pkgs/development/interpreters/clojure/obb.nix b/pkgs/development/interpreters/clojure/obb.nix index adb7a9261739..d6717c4ec701 100644 --- a/pkgs/development/interpreters/clojure/obb.nix +++ b/pkgs/development/interpreters/clojure/obb.nix @@ -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; }; } diff --git a/pkgs/development/tools/bbin/default.nix b/pkgs/development/tools/bbin/default.nix index d0956845092f..3bbece578ab4 100644 --- a/pkgs/development/tools/bbin/default.nix +++ b/pkgs/development/tools/bbin/default.nix @@ -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 ]; }; } diff --git a/pkgs/development/tools/neil/default.nix b/pkgs/development/tools/neil/default.nix index 4d162946226c..1052e174a725 100644 --- a/pkgs/development/tools/neil/default.nix +++ b/pkgs/development/tools/neil/default.nix @@ -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; { diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 9357c0743388..9f7e8504d958 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -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