build.tools.nix/mkClojureLib.nix

61 lines
1.3 KiB
Nix
Raw Normal View History

2022-05-29 10:34:35 -07:00
{ lib, stdenv, callPackage, jre, clojure, build-tools-jar, writeScript
2022-05-29 10:04:07 -07:00
, writeText }:
{ src, name, group, version, clj-deps, src-paths }:
2022-05-29 09:34:32 -07:00
with lib;
let
build-tools-deps = writeText "deps.edn" ''
{ :aliases
{ :build
{ :ns-default build
:replace-deps {
io.github.clojure/tools.build {
:local/root "${build-tools-jar}"
}
}
}
}
}
'';
deps = callPackage clj-deps { };
2022-05-29 10:35:25 -07:00
classpath = deps.makeClasspaths { };
2022-05-29 09:34:32 -07:00
uberjar-script = writeScript "uberjar-builder.rb" ''
${ruby}/bin/ruby
${readFile ./resources/uberjar-builder.rb}
'';
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 = [ jre ];
buildInputs = [ build-tools-jar ] ++ (map (x: x.paths) deps.packages);
buildPhase = ''
HOME=$TEMP/home
mkdir -p $HOME
mkdir -p ${target}
2022-05-29 10:34:35 -07:00
clojure \
2022-05-29 10:38:53 -07:00
-Scp ${classpath} \
2022-05-29 10:34:35 -07:00
-Sdeps ${build-tools-deps} \
-T:build \
lib-uberjar \
:project ${group}/${name} \
:version ${version}" \
2022-05-29 10:38:53 -07:00
:srcs ${concatStringsSep "," src-paths}" \
2022-05-29 10:34:35 -07:00
:target ${target}
2022-05-29 09:34:32 -07:00
'';
installPhase = ''
mv ${target}/${name}-${version}-standalone.jar $out
'';
}