1{
2 lib,
3 stdenv,
4 fetchurl,
5 installShellFiles,
6 jdk,
7 rlwrap,
8 makeWrapper,
9 writeScript,
10}:
11
12stdenv.mkDerivation (finalAttrs: {
13 pname = "clojure";
14 version = "1.12.0.1530";
15
16 src = fetchurl {
17 # https://github.com/clojure/brew-install/releases
18 url = "https://github.com/clojure/brew-install/releases/download/${finalAttrs.version}/clojure-tools-${finalAttrs.version}.tar.gz";
19 hash = "sha256-D/JLioEmujnTLeeEoIdnxd8lk4TLdsbuPbTWECcF7Uk=";
20 };
21
22 nativeBuildInputs = [
23 installShellFiles
24 makeWrapper
25 ];
26
27 # See https://github.com/clojure/brew-install/blob/1.10.3/src/main/resources/clojure/install/linux-install.sh
28 installPhase =
29 let
30 binPath = lib.makeBinPath [
31 rlwrap
32 jdk
33 ];
34 in
35 ''
36 runHook preInstall
37
38 clojure_lib_dir=$out
39 bin_dir=$out/bin
40
41 echo "Installing libs into $clojure_lib_dir"
42 install -Dm644 deps.edn "$clojure_lib_dir/deps.edn"
43 install -Dm644 example-deps.edn "$clojure_lib_dir/example-deps.edn"
44 install -Dm644 tools.edn "$clojure_lib_dir/tools.edn"
45 install -Dm644 exec.jar "$clojure_lib_dir/libexec/exec.jar"
46 install -Dm644 clojure-tools-${finalAttrs.version}.jar "$clojure_lib_dir/libexec/clojure-tools-${finalAttrs.version}.jar"
47
48 echo "Installing clojure and clj into $bin_dir"
49 substituteInPlace clojure --replace PREFIX $out
50 substituteInPlace clj --replace BINDIR $bin_dir
51 install -Dm755 clojure "$bin_dir/clojure"
52 install -Dm755 clj "$bin_dir/clj"
53
54 wrapProgram $bin_dir/clojure --prefix PATH : $out/bin:${binPath}
55 wrapProgram $bin_dir/clj --prefix PATH : $out/bin:${binPath}
56
57 installManPage clj.1 clojure.1
58
59 runHook postInstall
60 '';
61
62 doInstallCheck = true;
63
64 installCheckPhase = ''
65 CLJ_CONFIG=$TMPDIR CLJ_CACHE=$TMPDIR/.clj_cache $out/bin/clojure \
66 -Spath \
67 -Sverbose \
68 -Scp $out/libexec/clojure-tools-${finalAttrs.version}.jar
69 '';
70
71 passthru.updateScript = writeScript "update-clojure" ''
72 #!/usr/bin/env nix-shell
73 #!nix-shell -i bash -p curl common-updater-scripts jq
74
75 set -euo pipefail
76 shopt -s inherit_errexit
77
78 # `jq -r '.[0].name'` results in `v0.0`
79 latest_version="$(curl \
80 ''${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} \
81 -fsL "https://api.github.com/repos/clojure/brew-install/tags" \
82 | jq -r '.[1].name')"
83
84 update-source-version clojure "$latest_version"
85 '';
86
87 passthru.jdk = jdk;
88
89 meta = with lib; {
90 description = "Lisp dialect for the JVM";
91 homepage = "https://clojure.org/";
92 sourceProvenance = with sourceTypes; [ binaryBytecode ];
93 license = licenses.epl10;
94 longDescription = ''
95 Clojure is a dynamic programming language that targets the Java
96 Virtual Machine. It is designed to be a general-purpose language,
97 combining the approachability and interactive development of a
98 scripting language with an efficient and robust infrastructure for
99 multithreaded programming. Clojure is a compiled language - it
100 compiles directly to JVM bytecode, yet remains completely
101 dynamic. Every feature supported by Clojure is supported at
102 runtime. Clojure provides easy access to the Java frameworks, with
103 optional type hints and type inference, to ensure that calls to Java
104 can avoid reflection.
105
106 Clojure is a dialect of Lisp, and shares with Lisp the code-as-data
107 philosophy and a powerful macro system. Clojure is predominantly a
108 functional programming language, and features a rich set of immutable,
109 persistent data structures. When mutable state is needed, Clojure
110 offers a software transactional memory system and reactive Agent
111 system that ensure clean, correct, multithreaded designs.
112 '';
113 maintainers = with maintainers; [ jlesquembre ];
114 platforms = platforms.unix;
115 };
116})