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