build.tools.nix/mkClojureLib.nix

49 lines
1.1 KiB
Nix
Raw Normal View History

{ lib, stdenv, callPackage, clojure, build-tools-jar, writeText, 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
build-tools-deps = toEDN {
aliases.build = {
ns-build = "'build";
replace-deps."'io.github.clojure/tools.build"."local/root" =
"${build-tools-jar}";
};
};
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-29 09:34:32 -07:00
name = name;
src = src;
nativeBuildInputs = [ clojure ];
buildInputs = (map (x: x.paths) clj-deps.packages);
2022-05-29 09:34:32 -07:00
2022-05-29 10:58:01 -07:00
buildPhase = ''
HOME=$TEMP/home
mkdir -p $HOME
mkdir -p ${target}
clojure \
-Scp .:${build-tools-jar}:${classpath} \
-Sdeps ${builtins.trace build-tools-deps build-tools-deps} \
2022-05-29 22:35:28 -07:00
-X:build \
2022-05-29 10:58:01 -07:00
lib-uberjar \
:project ${group}/${name} \
:version ${version} \
:srcs ${concatStringsSep "," src-paths} \
:target ${target}
'';
2022-05-29 09:34:32 -07:00
installPhase = ''
mv ${target}/${name}-${version}-standalone.jar $out
'';
}