build.tools.nix/mkClojureLib.nix

59 lines
1.3 KiB
Nix

{ lib, stdenv, callPackage, jre, ruby, clojure, build-tools-jar, writeScript
, writeText, ... }:
{ src, name, group, version, clj-deps, src-paths, ... }:
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 { };
classpath = clj-deps.makeClasspaths { };
uberjar-script = writeScript "uberjar-builder.rb" ''
${ruby}/bin/ruby
${readFile ./resources/uberjar-builder.rb}
'';
full-name = "${group}-${name}-${version}-standalone.jar";
target = "$TEMP/target";
in stdenv.mkDerivation {
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}
${uberjar-script}
--root=$PWD \
--classpath=${classpath} \
--target=${target} \
--project=${group}/${name} \
--version=${version} \
--build-deps=${built-tools-deps} \
--source-paths=${concatStringsSep "," src-paths}
'';
installPhase = ''
mv ${target}/${name}-${version}-standalone.jar $out
'';
}