-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdefault.nix
More file actions
180 lines (154 loc) · 5.46 KB
/
default.nix
File metadata and controls
180 lines (154 loc) · 5.46 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
{
sources ? import ./nix/sources.nix,
system ? builtins.currentSystem,
pkgs ?
import sources.nixpkgs {
overlays = [
(final: previous: {
defaultGemConfig = previous.defaultGemConfig // {
jekyll-github-metadata = attrs: {
dontBuild = false;
patches = [
(final.fetchpatch {
url = "https://github.com/jekyll/github-metadata/commit/17cc5af5e1fd95d98d43676610cc8a47969350ab.patch";
hash = "sha256-dUqvnYsjfG5xQIYS48B3xz0GLVYo2BrDAnYUafmDFKw=";
relative = "lib";
stripLen = 1;
extraPrefix = "lib/jekyll-github-metadata/";
})
];
};
};
})
];
config = {};
inherit system;
},
doCheck ? true,
buildGitHubPages ? true,
dependenciesHash ? "sha256-LJQfV426han/+H9ejUla7JvN1LS/c9l3e7hODs4Z7Kg=",
}:
pkgs.stdenvNoCC.mkDerivation rec {
pname = "DiffDetective";
# The single source of truth for the version number is stored in `pom.xml`.
# Hence, this XML file needs to be parsed to extract the current version.
version = pkgs.lib.removeSuffix "\n" (pkgs.lib.readFile
(pkgs.runCommandLocal "DiffDetective-version" {}
"${pkgs.xq-xml}/bin/xq -x '/project/version' ${./pom.xml} > $out"));
src = with pkgs.lib.fileset;
toSource {
root = ./.;
fileset = gitTracked ./.;
};
nativeBuildInputs = with pkgs; [
maven
makeWrapper
graphviz
] ++ pkgs.lib.optional buildGitHubPages (ruby.withPackages (pkgs: with pkgs; [
github-pages
jekyll-theme-cayman
]));
# Maven needs to download necessary dependencies which is impure because it
# requires network access. Hence, we download all dependencies as a
# fixed-output derivation. This also serves as a nice cache.
mavenRepo = pkgs.stdenv.mkDerivation {
pname = "${pname}-mavenRepo";
inherit version;
src = pkgs.lib.sourceByRegex ./. ["^pom.xml$" "^local-maven-repo(/.*)?$"];
nativeBuildInputs = with pkgs; [maven];
buildPhase = ''
runHook preBuild
mvn org.apache.maven.plugins:maven-dependency-plugin:3.6.0:go-offline -Dmaven.repo.local="$out"
runHook postBuild
'';
# keep only *.{pom,jar,sha1,nbm} and delete all ephemeral files with lastModified timestamps inside
installPhase = ''
runHook preInstall
find "$out" -type f \
\( -not \( -name "*.pom" -o -name "*.jar" -o -name "*.sha1" -o -name "*.nbm" \) \
-o -name "maven-metadata*" \) \
-delete
runHook postInstall
'';
dontFixup = true;
dontConfigure = true;
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = dependenciesHash;
};
# - `out` contains jars, an executable wrapper and optionally documentation
# (see `buildGitHubPages`)
# - `maven` contains a local maven repository with DiffDetective and all its
# build-time and run-time dependencies.
outputs = ["out" "maven"];
jre-minimal = pkgs.callPackage (import "${sources.nixpkgs}/pkgs/development/compilers/openjdk/jre.nix") {
modules = ["java.base" "java.desktop"];
};
buildPhase = ''
runHook preBuild
mvn() {
command mvn --offline -Dmaven.repo.local="$mavenRepo" "$@"
}
${
# Build the documentation before the code because we don't want to include
# the generated files in the GitHub Pages
if buildGitHubPages
then ''
mvn javadoc:javadoc
JEKYLL_ENV=production PAGES_REPO_NWO=VariantSync/DiffDetective JEKYLL_BUILD_REVISION= PAGES_DISABLE_NETWORK=1 github-pages build
rm -rf _site/target
''
else ""
}
mvn -Dmaven.test.skip=true clean package
runHook postBuild
'';
inherit doCheck;
checkPhase = ''
runHook preTest
mvn --offline -Dmaven.repo.local="$mavenRepo" test
runHook postTest
'';
installPhase = ''
runHook preInstall
# install jars in "$out"
install -Dm644 "target/diffdetective-${version}.jar" "$out/share/java/DiffDetective.jar"
local jar="$out/share/java/DiffDetective/DiffDetective.jar"
install -Dm644 "target/diffdetective-${version}-jar-with-dependencies.jar" "$jar"
makeWrapper "${jre-minimal}/bin/java" "$out/bin/DiffDetective" --add-flags "-cp \"$jar\"" \
--prefix PATH : "${pkgs.graphviz}/bin"
# install documentation in "$out"
${
if buildGitHubPages
then ''
mkdir "$out/share/github-pages"
cp -r _site "$out/share/github-pages/DiffDetective"
''
else ""
}
# install DiffDetective in "$maven" by creating a copy of "$mavenRepo" as base
cp -r "$mavenRepo" "$maven"
chmod u+w -R "$maven"
mvn --offline -Dmaven.repo.local="$maven" -Dmaven.test.skip=true install
# keep only *.{pom,jar,sha1,nbm} and delete all ephemeral files with lastModified timestamps inside
find "$maven" -type f \
\( -not \( -name "*.pom" -o -name "*.jar" -o -name "*.sha1" -o -name "*.nbm" \) \
-o -name "maven-metadata*" \) \
-delete
runHook postInstall
'';
meta = {
description = "DiffDetective is a library for analysing changes to software product lines";
homepage = "https://github.com/VariantSync/DiffDetective";
license = pkgs.lib.licenses.lgpl3;
platforms = pkgs.maven.meta.platforms;
maintainers = [
{
name = "Benjamin Moosherr";
email = "[email protected]";
github = "ibbem";
githubId = 61984399;
}
];
};
}