build.tools.nix/mkClojureLib.nix

51 lines
1.2 KiB
Nix
Raw Normal View History

2022-05-31 13:07:35 -07:00
{ lib, stdenv, callPackage, clojure, jre, writeTextDir, writeShellScript, toEDN
}:
{ src, name, group, version, clj-deps, src-paths, build-tools-jar, ... }:
2022-05-29 09:34:32 -07:00
with lib;
let
2022-05-31 13:07:35 -07:00
build-tools-deps = writeTextDir "deps.edn" (toEDN {
aliases.build = {
2022-05-31 13:07:35 -07:00
ns-default = "'build";
extra-deps."'io.github.clojure/tools.build"."local/root" =
"${build-tools-jar}";
};
2022-05-30 17:48:28 -07:00
});
2022-05-30 17:39:48 -07:00
classpath = clj-deps.makeClasspaths { };
2022-05-29 09:34:32 -07:00
2022-05-31 13:07:35 -07:00
full-name = "${name}-${version}-standalone.jar";
2022-05-29 09:34:32 -07:00
target = "$TEMP/target";
2022-05-30 17:36:27 -07:00
build-script = writeShellScript "create-uberjar.sh" ''
HOME=$TEMP/home
mkdir -p $HOME
mkdir -p ${target}
2022-05-31 13:07:35 -07:00
clojure \
-Scp .:${build-tools-jar}:${classpath} \
-Sdeps ${build-tools-deps} \
-X:build \
2022-05-30 17:36:27 -07:00
lib-uberjar \
2022-05-31 13:07:35 -07:00
:project ${group}/${name} \
:version ${version} \
:src-dirs ${concatStringsSep "," src-paths} \
:target ${target}
2022-05-30 17:36:27 -07:00
'';
2022-05-29 09:45:16 -07:00
in stdenv.mkDerivation {
2022-05-31 13:07:35 -07:00
name = full-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-31 13:07:35 -07:00
buildPhase = builtins.trace "${build-script}" "${build-script}";
2022-05-29 09:34:32 -07:00
installPhase = ''
mv ${target}/${name}-${version}-standalone.jar $out
'';
}