52 lines
1.8 KiB
Nix
52 lines
1.8 KiB
Nix
{ lib, stdenv, build-tools-src, clojure, callPackage, writeText, gitignoreSource
|
|
, jre, ... }:
|
|
|
|
with lib;
|
|
let
|
|
base-name = "clojure-build-tools";
|
|
version = "0.8.2";
|
|
full-name = "${base-name}-${version}.jar";
|
|
cljdeps = callPackage ./deps.nix { };
|
|
classpath = cljdeps.makeClasspaths { };
|
|
dep-jars = splitString ":" classpath;
|
|
extract-jar = jar: "jar -xf ${jar}";
|
|
|
|
manifest = writeText "MANIFEST.MF" ''
|
|
Manifest-Version: 1.0
|
|
|
|
'';
|
|
|
|
java-compile = ns:
|
|
''java -cp .:${classpath} clojure.main -e "(compile ${ns})"'';
|
|
head-or-null = lst: if (lst == [ ]) then null else head lst;
|
|
matches-ext = ext: filename: type:
|
|
(builtins.match ".+[.]${ext}$" filename) != null;
|
|
strip-ext = ext: filename:
|
|
head-or-null (builtins.match "(.+)[.]${ext}$" filename);
|
|
ext-files = ext: path:
|
|
attrNames (filterAttrs (matches-ext "clj") (builtins.readDir path));
|
|
tasks = map (replaceStrings [ "_" ] [ "-" ]) (map (strip-ext "clj")
|
|
(ext-files "clj"
|
|
"${build-tools-src}/src/main/clojure/clojure/tools/build/tasks"));
|
|
task-namespaces = map (ns: "'clojure.tools.build.tasks.${ns}") tasks;
|
|
all-namespaces = [ "'clojure.tools.build.api" ] ++ task-namespaces;
|
|
compile-code = concatStringsSep " " (map (ns: "(compile ns)") all-namespaces);
|
|
|
|
in stdenv.mkDerivation {
|
|
name = full-name;
|
|
src = gitignoreSource "${build-tools-src}/src/main/clojure";
|
|
nativeBuildInputs = [ jre ];
|
|
buildInputs = map (x: x.paths) cljdeps.packages;
|
|
buildPhase = ''
|
|
mkdir classes
|
|
HOME=.
|
|
${concatStringsSep "\n" (map extract-jar dep-jars)}
|
|
${concatStringsSep "\n" (map java-compile all-namespaces)}
|
|
jar cmf ${manifest} ./out.jar -C . cljs cognitect com javax mozilla plugin.xml about.html clojure cognitect_aws_http.edn data_readers.cljc licenses org
|
|
'';
|
|
|
|
installPhase = ''
|
|
cp out.jar $out
|
|
'';
|
|
}
|