-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
derivation.nix
74 lines (66 loc) · 2.35 KB
/
derivation.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{ lib, writeText, stdenv, jdk, maven, makeWrapper, nix-gitignore
, bootstrap ? false, buildMavenRepositoryFromLockFile }:
let
repository = (if bootstrap then
stdenv.mkDerivation {
name = "bootstrap-repository";
buildInputs = [ jdk maven ];
src = nix-gitignore.gitignoreSource [] ./.;
buildPhase = ''
mkdir $out
while mvn package -Dmaven.repo.local=$out -Dmaven.wagon.rto=5000; [ $? = 1 ]; do
echo "timeout, restart maven to continue downloading"
done
'';
# keep only *.{pom,jar,sha1,nbm} and delete all ephemeral files with lastModified timestamps inside
installPhase = ''
find $out -type f \
-name \*.lastUpdated -or \
-name resolver-status.properties -or \
-name _remote.repositories \
-delete
'';
# don't do any fixup
dontFixup = true;
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = "09jx8kpj0wsi7rshczfpkp77dpfhybdrfkazf1i3s48s3kckz32r";
}
else
buildMavenRepositoryFromLockFile { file = ./mvn2nix-lock.json; });
in stdenv.mkDerivation rec {
pname = "mvn2nix";
version = "0.1";
name = "${pname}-${version}";
src = nix-gitignore.gitignoreSource [] ./.;
buildInputs = [ jdk maven makeWrapper ];
buildPhase = ''
echo "Using repository ${repository}"
# 'maven.repo.local' must be writable so copy it out of nix store
mvn package --offline -Dmaven.repo.local=${repository}
'';
installPhase = ''
# create the bin directory
mkdir -p $out/bin
# create a symbolic link for the lib directory
ln -s ${repository} $out/lib
# copy out the JAR
# Maven already setup the classpath to use m2 repository layout
# with the prefix of lib/
cp target/${name}.jar $out/
# create a wrapper that will automatically set the classpath
# this should be the paths from the dependency derivation
makeWrapper ${jdk}/bin/java $out/bin/${pname} \
--add-flags "-jar $out/${name}.jar" \
--set M2_HOME ${maven} \
--set JAVA_HOME ${jdk}
'';
meta = with lib; {
description =
"Easily package your Java applications for the Nix package manager.";
homepage = "https://github.com/fzakaria/mvn2nix";
license = licenses.mit;
maintainers = [ "[email protected]" ];
platforms = platforms.all;
};
}