-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
/
Copy pathwrapped.nix
65 lines (57 loc) · 2.11 KB
/
wrapped.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{
stdenvNoCC,
lib,
babashka-unwrapped,
callPackage,
makeWrapper,
installShellFiles,
rlwrap,
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
#
# NOTE In some cases, rlwrap prints some extra empty lines. That behavior can
# break some babashka scripts. For this reason, it is disabled by default. See:
# https://github.com/NixOS/nixpkgs/issues/246839
# https://github.com/NixOS/nixpkgs/pull/248207
withRlwrap ? false,
}:
stdenvNoCC.mkDerivation (finalAttrs: {
pname = "babashka";
inherit (babashka-unwrapped) version meta doInstallCheck;
dontUnpack = true;
dontBuild = true;
nativeBuildInputs = [
makeWrapper
installShellFiles
];
installPhase =
let
unwrapped-bin = "${babashka-unwrapped}/bin/bb";
in
''
mkdir -p $out/clojure_tools
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 JAVA_HOME ${jdkBabashka}
installShellCompletion --cmd bb --bash ${babashka-unwrapped}/share/bash-completion/completions/bb.bash
installShellCompletion --cmd bb --zsh ${babashka-unwrapped}/share/zsh/site-functions/_bb
installShellCompletion --cmd bb --fish ${babashka-unwrapped}/share/fish/vendor_completions.d/bb.fish
''
+ lib.optionalString withRlwrap ''
substituteInPlace $out/bin/bb \
--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;
})