99 } ,
1010 doCheck ? true ,
1111 buildGitHubPages ? true ,
12+ dependenciesHash ? "sha256-LJQfV426han/+H9ejUla7JvN1LS/c9l3e7hODs4Z7Kg=" ,
1213} :
1314pkgs . stdenvNoCC . mkDerivation rec {
1415 pname = "DiffDetective" ;
@@ -32,6 +33,9 @@ pkgs.stdenvNoCC.mkDerivation rec {
3233 jekyll-theme-cayman
3334 ] ) ) ;
3435
36+ # Maven needs to download necessary dependencies which is impure because it
37+ # requires network access. Hence, we download all dependencies as a
38+ # fixed-output derivation. This also serves as a nice cache.
3539 mavenRepo = pkgs . stdenv . mkDerivation {
3640 pname = "${ pname } -mavenRepo" ;
3741 inherit version ;
@@ -40,25 +44,38 @@ pkgs.stdenvNoCC.mkDerivation rec {
4044 nativeBuildInputs = with pkgs ; [ maven ] ;
4145
4246 buildPhase = ''
47+ runHook preBuild
48+
4349 mvn org.apache.maven.plugins:maven-dependency-plugin:3.6.0:go-offline -Dmaven.repo.local="$out"
50+
51+ runHook postBuild
4452 '' ;
4553
4654 # keep only *.{pom,jar,sha1,nbm} and delete all ephemeral files with lastModified timestamps inside
4755 installPhase = ''
56+ runHook preInstall
57+
4858 find "$out" -type f \
49- \( -name \*.lastUpdated -or \
50- -name resolver-status.properties -or \
51- -name _remote.repositories \) \
59+ \( -not \( -name "*.pom" -o -name "*.jar" -o -name "*.sha1" -o -name "*.nbm" \) \
60+ -o -name "maven-metadata*" \) \
5261 -delete
62+
63+ runHook postInstall
5364 '' ;
5465
5566 dontFixup = true ;
5667 dontConfigure = true ;
5768 outputHashAlgo = "sha256" ;
5869 outputHashMode = "recursive" ;
59- outputHash = "sha256-TYZP4XhM3ExLNC3H/QLch6LMVQxbR1LECwubMZn+RXY=" ;
70+ outputHash = dependenciesHash ;
6071 } ;
6172
73+ # - `out` contains jars, an executable wrapper and optionally documentation
74+ # (see `buildGitHubPages`)
75+ # - `maven` contains a local maven repository with DiffDetective and all its
76+ # build-time and run-time dependencies.
77+ outputs = [ "out" "maven" ] ;
78+
6279 jre-minimal = pkgs . callPackage ( import "${ sources . nixpkgs } /pkgs/development/compilers/openjdk/jre.nix" ) {
6380 modules = [ "java.base" "java.desktop" ] ;
6481 } ;
@@ -88,21 +105,24 @@ pkgs.stdenvNoCC.mkDerivation rec {
88105
89106 inherit doCheck ;
90107 checkPhase = ''
91- runHook postTest
108+ runHook preTest
92109
93110 mvn --offline -Dmaven.repo.local="$mavenRepo" test
94111
95112 runHook postTest
96113 '' ;
97114
98115 installPhase = ''
99- runHook postInstall
116+ runHook preInstall
100117
118+ # install jars in "$out"
119+ install -Dm644 "target/diffdetective-${ version } .jar" "$out/share/java/DiffDetective.jar"
101120 local jar="$out/share/java/DiffDetective/DiffDetective.jar"
102121 install -Dm644 "target/diffdetective-${ version } -jar-with-dependencies.jar" "$jar"
103122 makeWrapper "${ jre-minimal } /bin/java" "$out/bin/DiffDetective" --add-flags "-cp \"$jar\"" \
104123 --prefix PATH : "${ pkgs . graphviz } /bin"
105124
125+ # install documentation in "$out"
106126 ${
107127 if buildGitHubPages
108128 then ''
@@ -112,6 +132,17 @@ pkgs.stdenvNoCC.mkDerivation rec {
112132 else ""
113133 }
114134
135+ # install DiffDetective in "$maven" by creating a copy of "$mavenRepo" as base
136+ cp -r "$mavenRepo" "$maven"
137+ chmod u+w -R "$maven"
138+ mvn --offline -Dmaven.repo.local="$maven" -Dmaven.test.skip=true install
139+
140+ # keep only *.{pom,jar,sha1,nbm} and delete all ephemeral files with lastModified timestamps inside
141+ find "$maven" -type f \
142+ \( -not \( -name "*.pom" -o -name "*.jar" -o -name "*.sha1" -o -name "*.nbm" \) \
143+ -o -name "maven-metadata*" \) \
144+ -delete
145+
115146 runHook postInstall
116147 '' ;
117148
0 commit comments