build.tools.nix/mkClojureLib.nix

56 lines
1.2 KiB
Nix
Raw Normal View History

2022-05-29 10:50:26 -07:00
{ lib, stdenv, callPackage, clojure, build-tools-jar, writeTextDir }:
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 10:49:44 -07:00
build-tools-deps = writeTextDir "deps.edn" ''
2022-05-29 09:34:32 -07:00
{ :aliases
{ :build
{ :ns-default build
:replace-deps {
io.github.clojure/tools.build {
:local/root "${build-tools-jar}"
}
}
}
}
}
'';
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:46:20 -07:00
buildPhase = let
cmd = ''
HOME=$TEMP/home
mkdir -p $HOME
mkdir -p ${target}
clojure \
2022-05-29 10:48:37 -07:00
-Scp .:${build-tools-jar}:${classpath} \
2022-05-29 10:49:44 -07:00
-Sdeps ${build-tools-deps}/deps.edn \
2022-05-29 10:46:20 -07:00
-X:build \
lib-uberjar \
:project ${group}/${name} \
2022-05-29 10:48:37 -07:00
:version ${version} \
:srcs ${concatStringsSep "," src-paths} \
2022-05-29 10:46:20 -07:00
:target ${target}
'';
in builtins.trace cmd cmd;
2022-05-29 09:34:32 -07:00
installPhase = ''
mv ${target}/${name}-${version}-standalone.jar $out
'';
}