2023-03-24 00:07:29 +00:00
|
|
|
|
{ lib
|
|
|
|
|
, buildGraalvmNativeImage
|
|
|
|
|
, graalvmCEPackages
|
|
|
|
|
, fetchurl
|
2023-07-15 17:15:38 +00:00
|
|
|
|
, writeScript
|
2023-11-16 04:20:00 +00:00
|
|
|
|
, installShellFiles
|
2023-07-15 17:15:38 +00:00
|
|
|
|
}:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
2023-10-19 13:55:26 +00:00
|
|
|
|
let
|
|
|
|
|
babashka-unwrapped = buildGraalvmNativeImage rec {
|
|
|
|
|
pname = "babashka-unwrapped";
|
2024-04-21 15:54:59 +00:00
|
|
|
|
version = "1.3.190";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
2023-10-19 13:55:26 +00:00
|
|
|
|
src = fetchurl {
|
|
|
|
|
url = "https://github.com/babashka/babashka/releases/download/v${version}/babashka-${version}-standalone.jar";
|
2024-04-21 15:54:59 +00:00
|
|
|
|
sha256 = "sha256-zGWUuFyCOZXrcAOJ2sGvzvfJbFti1IlDS1gx9Oye9fg=";
|
2023-10-19 13:55:26 +00:00
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
2023-10-19 13:55:26 +00:00
|
|
|
|
graalvmDrv = graalvmCEPackages.graalvm-ce;
|
|
|
|
|
|
|
|
|
|
executable = "bb";
|
|
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
|
nativeBuildInputs = [ installShellFiles ];
|
2023-10-19 13:55:26 +00:00
|
|
|
|
|
|
|
|
|
extraNativeImageBuildArgs = [
|
|
|
|
|
"-H:+ReportExceptionStackTraces"
|
|
|
|
|
"--no-fallback"
|
|
|
|
|
"--native-image-info"
|
|
|
|
|
"--enable-preview"
|
2021-06-01 10:57:12 +00:00
|
|
|
|
];
|
2023-10-19 13:55:26 +00:00
|
|
|
|
|
|
|
|
|
doInstallCheck = true;
|
|
|
|
|
|
|
|
|
|
installCheckPhase = ''
|
2023-11-16 04:20:00 +00:00
|
|
|
|
$out/bin/bb --version | fgrep '${version}'
|
|
|
|
|
$out/bin/bb '(+ 1 2)' | fgrep '3'
|
|
|
|
|
$out/bin/bb '(vec (dedupe *input*))' <<< '[1 1 1 1 2]' | fgrep '[1 2]'
|
|
|
|
|
$out/bin/bb '(prn "bépo àê")' | fgrep 'bépo àê'
|
2024-02-07 01:22:34 +00:00
|
|
|
|
$out/bin/bb '(:out (babashka.process/sh "echo" "ä"))' | fgrep 'ä'
|
2023-10-19 13:55:26 +00:00
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
postInstall = ''
|
2023-11-16 04:20:00 +00:00
|
|
|
|
installShellCompletion --cmd bb --bash ${./completions/bb.bash}
|
|
|
|
|
installShellCompletion --cmd bb --zsh ${./completions/bb.zsh}
|
|
|
|
|
installShellCompletion --cmd bb --fish ${./completions/bb.fish}
|
2023-10-19 13:55:26 +00:00
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
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; {
|
2024-06-20 14:57:18 +00:00
|
|
|
|
description = "Clojure babushka for the grey areas of Bash";
|
2023-10-19 13:55:26 +00:00
|
|
|
|
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
|
|
|
|
|
];
|
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
2023-10-19 13:55:26 +00:00
|
|
|
|
in
|
|
|
|
|
babashka-unwrapped
|