worther/worther.nix

40 lines
976 B
Nix
Raw Permalink Normal View History

2021-08-03 07:20:06 -07:00
{ pkgs ? import <nixpkgs> {}, ... }:
2021-08-03 11:44:54 -07:00
2021-08-03 07:20:06 -07:00
let
cljdeps = pkgs.callPackage ./deps.nix {};
classpath = cljdeps.makeClasspaths {};
exec-name = "worther";
main-class = "worther.core";
manifest = pkgs.writeText "${exec-name}-MANIFEST.MF" ''
Manifest-Version: 1.0
Main-Class: ${main-class}
'';
in pkgs.stdenv.mkDerivation {
name = exec-name;
nativeBuildInputs = with pkgs; [ jre makeWrapper ];
2021-08-03 11:44:54 -07:00
buildInputs = map (x: x.paths) cljdeps.packages;
2021-08-03 07:20:06 -07:00
src = ./src;
phases = [ "unpackPhase" "buildPhase" "installPhase" ];
buildPhase = ''
mkdir classes
2021-08-03 14:42:50 -07:00
java -cp .:${classpath} clojure.main -e "(compile '${main-class})"
2021-08-03 07:20:06 -07:00
jar cmf ${manifest} out.jar -C classes worther
'';
installPhase = ''
mkdir -p $out/bin
mkdir -p $out/share/java
cp out.jar $out/share/java/${exec-name}.jar
makeWrapper ${pkgs.jdk}/bin/java $out/bin/${exec-name} \
--add-flags "-cp ${classpath}:$out/share/java/${exec-name}.jar ${main-class}"
'';
}