build.tools.nix/mkClojureLib.nix

53 lines
1.3 KiB
Nix
Raw Normal View History

{ lib, stdenv, callPackage, clojure, jre, build-tools-jar, writeTextDir
, writeShellScript, toEDN }:
2022-05-29 10:04:07 -07:00
{ src, name, group, version, clj-deps, src-paths }:
2022-05-29 09:34:32 -07:00
with lib;
let
2022-05-29 22:57:25 -07:00
2022-05-30 16:46:55 -07:00
build-tools-deps = writeTextDir "deps.edn" (toEDN {
aliases.build = {
ns-build = "'build";
replace-deps."'io.github.clojure/tools.build"."local/root" =
"${build-tools-jar}";
};
2022-05-30 16:46:55 -07:00
});
2022-05-29 09:34:32 -07:00
classpath = clj-deps.makeClasspaths { };
2022-05-29 09:34:32 -07:00
full-name = "${group}-${name}-${version}-standalone.jar";
target = "$TEMP/target";
2022-05-29 09:45:16 -07:00
in stdenv.mkDerivation {
2022-05-30 17:35:11 -07:00
name = builtins.trace name name;
2022-05-29 09:34:32 -07:00
src = src;
2022-05-30 16:54:45 -07:00
nativeBuildInputs = [ clojure jre ];
buildInputs = (map (x: x.paths) clj-deps.packages);
2022-05-29 09:34:32 -07:00
2022-05-30 17:02:52 -07:00
buildPhase = let
script = writeShellScript "create-uberjar.sh" ''
HOME=$TEMP/home
mkdir -p $HOME
mkdir -p ${target}
clojure \
-Scp .:${build-tools-jar}:${classpath} \
-Sdeps ${builtins.trace build-tools-deps build-tools-deps} \
-X:build \
lib-uberjar \
:project ${group}/${name} \
:version ${version} \
:srcs ${concatStringsSep "," src-paths} \
:target ${target}
'';
script-call = "${script}";
in builtins.trace script-call script-call;
2022-05-29 09:34:32 -07:00
installPhase = ''
mv ${target}/${name}-${version}-standalone.jar $out
'';
}