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