lol
1{ lib
2, buildGraalvmNativeImage
3, graalvmCEPackages
4, removeReferencesTo
5, fetchurl
6, writeScript
7, installShellFiles
8}:
9
10let
11 babashka-unwrapped = buildGraalvmNativeImage rec {
12 pname = "babashka-unwrapped";
13 version = "1.3.186";
14
15 src = fetchurl {
16 url = "https://github.com/babashka/babashka/releases/download/v${version}/babashka-${version}-standalone.jar";
17 sha256 = "sha256-T7inTJHSnUySituU0fcgZ0xWjIY3yb8BlSakqym67ew=";
18 };
19
20 graalvmDrv = graalvmCEPackages.graalvm-ce;
21
22 executable = "bb";
23
24 nativeBuildInputs = [ removeReferencesTo installShellFiles ];
25
26 extraNativeImageBuildArgs = [
27 "-H:+ReportExceptionStackTraces"
28 "--no-fallback"
29 "--native-image-info"
30 "--enable-preview"
31 ];
32
33 doInstallCheck = true;
34
35 installCheckPhase = ''
36 $out/bin/bb --version | fgrep '${version}'
37 $out/bin/bb '(+ 1 2)' | fgrep '3'
38 $out/bin/bb '(vec (dedupe *input*))' <<< '[1 1 1 1 2]' | fgrep '[1 2]'
39 $out/bin/bb '(prn "bépo àê")' | fgrep 'bépo àê'
40 '';
41
42 # As of v1.2.174, this will remove references to ${graalvmDrv}/conf/chronology,
43 # not sure the implications of this but this file is not available in
44 # graalvm-ce anyway.
45 postInstall = ''
46 remove-references-to -t ${graalvmDrv} $out/bin/${executable}
47 installShellCompletion --cmd bb --bash ${./completions/bb.bash}
48 installShellCompletion --cmd bb --zsh ${./completions/bb.zsh}
49 installShellCompletion --cmd bb --fish ${./completions/bb.fish}
50 '';
51
52 passthru.updateScript = writeScript "update-babashka" ''
53 #!/usr/bin/env nix-shell
54 #!nix-shell -i bash -p curl common-updater-scripts jq libarchive
55
56 set -euo pipefail
57 shopt -s inherit_errexit
58
59 latest_version="$(curl \
60 ''${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} \
61 -fsL "https://api.github.com/repos/babashka/babashka/releases/latest" \
62 | jq -r '.tag_name')"
63
64 if [ "$(update-source-version babashka-unwrapped "''${latest_version/v/}" --print-changes)" = "[]" ]; then
65 # no need to update babashka.clojure-tools when babashka-unwrapped wasn't updated
66 exit 0
67 fi
68
69 clojure_tools_version=$(curl \
70 -fsL \
71 "https://github.com/babashka/babashka/releases/download/''${latest_version}/babashka-''${latest_version/v/}-standalone.jar" \
72 | bsdtar -qxOf - borkdude/deps.clj \
73 | ${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'.\" {})))")
74
75 update-source-version babashka.clojure-tools "$clojure_tools_version" \
76 --file="pkgs/development/interpreters/babashka/clojure-tools.nix"
77 '';
78
79 meta = with lib; {
80 description = "A Clojure babushka for the grey areas of Bash";
81 longDescription = ''
82 The main idea behind babashka is to leverage Clojure in places where you
83 would be using bash otherwise.
84
85 As one user described it:
86
87 I’m quite at home in Bash most of the time, but there’s a substantial
88 grey area of things that are too complicated to be simple in bash, but
89 too simple to be worth writing a clj/s script for. Babashka really
90 seems to hit the sweet spot for those cases.
91
92 Goals:
93
94 - Low latency Clojure scripting alternative to JVM Clojure.
95 - Easy installation: grab the self-contained binary and run. No JVM needed.
96 - Familiarity and portability:
97 - Scripts should be compatible with JVM Clojure as much as possible
98 - Scripts should be platform-independent as much as possible. Babashka
99 offers support for linux, macOS and Windows.
100 - Allow interop with commonly used classes like java.io.File and System
101 - Multi-threading support (pmap, future, core.async)
102 - Batteries included (tools.cli, cheshire, ...)
103 - Library support via popular tools like the clojure CLI
104 '';
105 homepage = "https://github.com/babashka/babashka";
106 changelog = "https://github.com/babashka/babashka/blob/v${version}/CHANGELOG.md";
107 sourceProvenance = with sourceTypes; [ binaryBytecode ];
108 license = licenses.epl10;
109 maintainers = with maintainers; [
110 bandresen
111 bhougland
112 DerGuteMoritz
113 jlesquembre
114 thiagokokada
115 ];
116 };
117 };
118in
119babashka-unwrapped