From 9e2ee4c84610e0a3aa83f7ca7f8bc433d3baecba Mon Sep 17 00:00:00 2001 From: Moritz Heidkamp Date: Tue, 26 Sep 2023 18:40:59 +0200 Subject: [PATCH] babashka: use upstream version of Clojure tools As recommended by @borkdude[1], we should use the Clojure tools version included in a particular upstream release since the code might not always work with more recent versions. [1] https://github.com/borkdude/deps.clj/issues/113#issuecomment-1735805109 --- .../interpreters/babashka/clojure-tools.nix | 15 ++ .../interpreters/babashka/default.nix | 189 ++++++++++-------- .../interpreters/babashka/wrapped.nix | 21 +- 3 files changed, 131 insertions(+), 94 deletions(-) create mode 100644 pkgs/development/interpreters/babashka/clojure-tools.nix diff --git a/pkgs/development/interpreters/babashka/clojure-tools.nix b/pkgs/development/interpreters/babashka/clojure-tools.nix new file mode 100644 index 0000000000000..b95a40e12a171 --- /dev/null +++ b/pkgs/development/interpreters/babashka/clojure-tools.nix @@ -0,0 +1,15 @@ +# This file tracks the Clojure tools version required by babashka. +# See https://github.com/borkdude/deps.clj#deps_clj_tools_version for background. +# The `updateScript` provided in default.nix takes care of keeping it in sync, as well. +{ clojure +, fetchurl +}: +clojure.overrideAttrs (previousAttrs: { + pname = "babashka-clojure-tools"; + version = "1.11.1.1403"; + + src = fetchurl { + url = previousAttrs.src.url; + hash = "sha256-bVNHEEzpPanPF8pfDP51d13bxv9gZGzqczNmFQOk6zI="; + }; +}) diff --git a/pkgs/development/interpreters/babashka/default.nix b/pkgs/development/interpreters/babashka/default.nix index 1ae30244b2051..3b1874a605ded 100644 --- a/pkgs/development/interpreters/babashka/default.nix +++ b/pkgs/development/interpreters/babashka/default.nix @@ -6,94 +6,109 @@ , writeScript }: -buildGraalvmNativeImage rec { - pname = "babashka-unwrapped"; - version = "1.3.184"; +let + babashka-unwrapped = buildGraalvmNativeImage rec { + pname = "babashka-unwrapped"; + version = "1.3.184"; - src = fetchurl { - url = "https://github.com/babashka/babashka/releases/download/v${version}/babashka-${version}-standalone.jar"; - sha256 = "sha256-O3pLELYmuuB+Bf1vHTWQ+u7Ymi3qYiMRpCwvEq+GeBQ="; - }; + src = fetchurl { + url = "https://github.com/babashka/babashka/releases/download/v${version}/babashka-${version}-standalone.jar"; + sha256 = "sha256-O3pLELYmuuB+Bf1vHTWQ+u7Ymi3qYiMRpCwvEq+GeBQ="; + }; - graalvmDrv = graalvmCEPackages.graalvm-ce; - - executable = "bb"; - - nativeBuildInputs = [ removeReferencesTo ]; - - extraNativeImageBuildArgs = [ - "-H:+ReportExceptionStackTraces" - "--no-fallback" - "--native-image-info" - "--enable-preview" - ]; - - doInstallCheck = true; - - installCheckPhase = '' - $out/bin/bb --version | grep '${version}' - $out/bin/bb '(+ 1 2)' | grep '3' - $out/bin/bb '(vec (dedupe *input*))' <<< '[1 1 1 1 2]' | grep '[1 2]' - ''; - - # As of v1.2.174, this will remove references to ${graalvmDrv}/conf/chronology, - # not sure the implications of this but this file is not available in - # graalvm-ce anyway. - postInstall = '' - remove-references-to -t ${graalvmDrv} $out/bin/${executable} - ''; - - passthru.updateScript = writeScript "update-babashka" '' - #!/usr/bin/env nix-shell - #!nix-shell -i bash -p curl common-updater-scripts jq - - set -euo pipefail - - readonly latest_version="$(curl \ - ''${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} \ - -s "https://api.github.com/repos/babashka/babashka/releases/latest" \ - | jq -r '.tag_name')" - - # v0.6.2 -> 0.6.2 - update-source-version babashka "''${latest_version/v/}" - ''; - - meta = with lib; { - description = "A Clojure babushka for the grey areas of Bash"; - longDescription = '' - The main idea behind babashka is to leverage Clojure in places where you - would be using bash otherwise. - - As one user described it: - - I’m quite at home in Bash most of the time, but there’s a substantial - grey area of things that are too complicated to be simple in bash, but - 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 - ''; - homepage = "https://github.com/babashka/babashka"; - changelog = "https://github.com/babashka/babashka/blob/v${version}/CHANGELOG.md"; - sourceProvenance = with sourceTypes; [ binaryBytecode ]; - license = licenses.epl10; - maintainers = with maintainers; [ - bandresen - bhougland - DerGuteMoritz - jlesquembre - thiagokokada + graalvmDrv = graalvmCEPackages.graalvm-ce; + + executable = "bb"; + + nativeBuildInputs = [ removeReferencesTo ]; + + extraNativeImageBuildArgs = [ + "-H:+ReportExceptionStackTraces" + "--no-fallback" + "--native-image-info" + "--enable-preview" ]; + + doInstallCheck = true; + + installCheckPhase = '' + $out/bin/bb --version | grep '${version}' + $out/bin/bb '(+ 1 2)' | grep '3' + $out/bin/bb '(vec (dedupe *input*))' <<< '[1 1 1 1 2]' | grep '[1 2]' + ''; + + # As of v1.2.174, this will remove references to ${graalvmDrv}/conf/chronology, + # not sure the implications of this but this file is not available in + # graalvm-ce anyway. + postInstall = '' + remove-references-to -t ${graalvmDrv} $out/bin/${executable} + ''; + + passthru.updateScript = writeScript "update-babashka" '' + #!/usr/bin/env nix-shell + #!nix-shell -i bash -p curl common-updater-scripts jq libarchive + + set -euo pipefail + shopt -s inherit_errexit + + latest_version="$(curl \ + ''${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} \ + -fsL "https://api.github.com/repos/babashka/babashka/releases/latest" \ + | jq -r '.tag_name')" + + if [ "$(update-source-version babashka-unwrapped "''${latest_version/v/}" --print-changes)" = "[]" ]; then + # no need to update babashka.clojure-tools when babashka-unwrapped wasn't updated + exit 0 + fi + + clojure_tools_version=$(curl \ + -fsL \ + "https://github.com/babashka/babashka/releases/download/''${latest_version}/babashka-''${latest_version/v/}-standalone.jar" \ + | bsdtar -qxOf - borkdude/deps.clj \ + | ${babashka-unwrapped}/bin/bb -I -o -e "(or (some->> *input* (filter #(= '(def version) (take 2 %))) first last last last) (throw (ex-info \"Couldn't find expected '(def version ...)' form in 'borkdude/deps.clj'.\" {})))") + + update-source-version babashka.clojure-tools "$clojure_tools_version" \ + --file="pkgs/development/interpreters/babashka/clojure-tools.nix" + ''; + + meta = with lib; { + description = "A Clojure babushka for the grey areas of Bash"; + longDescription = '' + The main idea behind babashka is to leverage Clojure in places where you + would be using bash otherwise. + + As one user described it: + + I’m quite at home in Bash most of the time, but there’s a substantial + grey area of things that are too complicated to be simple in bash, but + 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 + ''; + homepage = "https://github.com/babashka/babashka"; + changelog = "https://github.com/babashka/babashka/blob/v${version}/CHANGELOG.md"; + sourceProvenance = with sourceTypes; [ binaryBytecode ]; + license = licenses.epl10; + maintainers = with maintainers; [ + bandresen + bhougland + DerGuteMoritz + jlesquembre + thiagokokada + ]; + }; }; -} +in +babashka-unwrapped diff --git a/pkgs/development/interpreters/babashka/wrapped.nix b/pkgs/development/interpreters/babashka/wrapped.nix index e82e56067ca7c..eb03045719f0a 100644 --- a/pkgs/development/interpreters/babashka/wrapped.nix +++ b/pkgs/development/interpreters/babashka/wrapped.nix @@ -1,11 +1,11 @@ { stdenvNoCC , lib , babashka-unwrapped -, clojure +, callPackage , makeWrapper , rlwrap - -, jdkBabashka ? clojure.jdk +, clojureToolsBabashka ? callPackage ./clojure-tools.nix { } +, jdkBabashka ? clojureToolsBabashka.jdk # rlwrap is a small utility to allow the editing of keyboard input, see # https://book.babashka.org/#_repl @@ -18,7 +18,7 @@ }: stdenvNoCC.mkDerivation (finalAttrs: { pname = "babashka"; - inherit (babashka-unwrapped) version meta doInstallCheck installCheckPhase; + inherit (babashka-unwrapped) version meta doInstallCheck; dontUnpack = true; dontBuild = true; @@ -29,13 +29,12 @@ stdenvNoCC.mkDerivation (finalAttrs: { 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/* + ln -s -t $out/clojure_tools ${clojureToolsBabashka}/*.edn + ln -s -t $out/clojure_tools ${clojureToolsBabashka}/libexec/* makeWrapper "${babashka-unwrapped}/bin/bb" "$out/bin/bb" \ --inherit-argv0 \ --set-default DEPS_CLJ_TOOLS_DIR $out/clojure_tools \ - --set-default DEPS_CLJ_TOOLS_VERSION ${clojure.version} \ --set-default JAVA_HOME ${jdkBabashka} '' + @@ -44,5 +43,13 @@ stdenvNoCC.mkDerivation (finalAttrs: { --replace '"${unwrapped-bin}"' '"${rlwrap}/bin/rlwrap" "${unwrapped-bin}"' ''; + installCheckPhase = '' + ${babashka-unwrapped.installCheckPhase} + # Needed for Darwin compat, see https://github.com/borkdude/deps.clj/issues/114 + export CLJ_CONFIG="$TMP/.clojure" + $out/bin/bb clojure --version | grep -wF '${clojureToolsBabashka.version}' + ''; + passthru.unwrapped = babashka-unwrapped; + passthru.clojure-tools = clojureToolsBabashka; })