Skip to content

Commit 07756a1

Browse files
authored
Merge pull request #151 from VariantSync/enhance-nix-setup
Enhance the nix setup
2 parents a963735 + abe6cfd commit 07756a1

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

.github/workflows/maven.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ jobs:
1616
runs-on: ubuntu-latest
1717

1818
steps:
19-
- uses: actions/checkout@v3
19+
- uses: actions/checkout@v4
2020
- name: Install Nix with cached packages
21-
uses: rikhuijzer/cache-install@v.1.1.3
21+
uses: rikhuijzer/cache-install@v1.1.4
2222
with:
2323
key: nix-${{ hashFiles('.github/workflows/maven.yml', 'default.nix', 'nix/**', 'pom.xml', 'local-maven-repo') }}
2424
nix_file: nix/github-workflow-dependencies.nix
2525
- name: Build
2626
run: nix-build
2727
- name: Upload Javadoc artifact
2828
if: ${{ github.event_name == 'push' && github.event.ref == 'refs/heads/main' }}
29-
uses: actions/upload-pages-artifact@v1
29+
uses: actions/upload-pages-artifact@v3
3030
with:
3131
path: result/share/github-pages/DiffDetective
3232

@@ -50,7 +50,7 @@ jobs:
5050
steps:
5151
- name: Publish Javadoc to Github Pages
5252
id: deployment
53-
uses: actions/deploy-pages@v1
53+
uses: actions/deploy-pages@v4
5454

5555
# Kill in progress deployments because only the newest version is relevant
5656
# and concurrent deployments cause CI failures.

default.nix

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
},
1010
doCheck ? true,
1111
buildGitHubPages ? true,
12+
dependenciesHash ? "sha256-LJQfV426han/+H9ejUla7JvN1LS/c9l3e7hODs4Z7Kg=",
1213
}:
1314
pkgs.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

Comments
 (0)