Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factor out fetcher of Maven dependencies #83725

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 5 additions & 14 deletions pkgs/applications/networking/cluster/hadoop/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, fetchurl, makeWrapper, pkgconfig, which, maven, cmake, jre, bash
{ stdenv, fetchurl, fetchMavenDeps, makeWrapper, pkgconfig, which, maven, cmake, jre, bash
, coreutils, glibc, protobuf2_5, fuse, snappy, zlib, bzip2, openssl, openssl_1_0_2
}:

Expand All @@ -19,19 +19,10 @@ let
'';

# perform fake build to make a fixed-output derivation of dependencies downloaded from maven central (~100Mb in ~3000 files)
fetched-maven-deps = stdenv.mkDerivation {
name = "hadoop-${version}-maven-deps";
inherit src postUnpack nativeBuildInputs buildInputs;
buildPhase = ''
while mvn package -Dmaven.repo.local=$out/.m2 ${mavenFlags} -Dmaven.wagon.rto=5000; [ $? = 1 ]; do
echo "timeout, restart maven to continue downloading"
done
'';
# keep only *.{pom,jar,xml,sha1,so,dll,dylib} and delete all ephemeral files with lastModified timestamps inside
installPhase = ''find $out/.m2 -type f -regex '.+\(\.lastUpdated\|resolver-status\.properties\|_remote\.repositories\)' -delete'';
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = dependencies-sha256;
fetched-maven-deps = fetchMavenDeps {
name = "hadoop-${version}";
sha256 = dependencies-sha256;
inherit src postUnpack nativeBuildInputs buildInputs mavenFlags;
};

nativeBuildInputs = [ maven cmake pkgconfig ];
Expand Down
25 changes: 6 additions & 19 deletions pkgs/applications/science/misc/gephi/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ stdenv, fetchFromGitHub, jdk, maven, javaPackages }:
{ stdenv, fetchFromGitHub, fetchMavenDeps, jdk, maven, javaPackages }:

let
pname = "gephi";
version = "0.9.2";

src = fetchFromGitHub {
Expand All @@ -11,27 +12,13 @@ let
};

# perform fake build to make a fixed-output derivation out of the files downloaded from maven central (120MB)
deps = stdenv.mkDerivation {
name = "gephi-${version}-deps";
inherit src;
buildInputs = [ jdk maven ];
buildPhase = ''
while mvn package -Dmaven.repo.local=$out/.m2 -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/.m2 -type f -regex '.+\(\.lastUpdated\|resolver-status\.properties\|_remote\.repositories\)' -delete'';
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = "1p7yf97dn0nvr005cbs6vdk3i341s8fya4kfccj8qqad2qgxflif";
deps = fetchMavenDeps {
inherit pname version src;
sha256 = "1p7yf97dn0nvr005cbs6vdk3i341s8fya4kfccj8qqad2qgxflif";
};
in
stdenv.mkDerivation {
pname = "gephi";
inherit version;

inherit src;
inherit pname version src;

buildInputs = [ jdk maven ];

Expand Down
32 changes: 32 additions & 0 deletions pkgs/build-support/fetch-maven-deps.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# WARNING: this method of fetching dependencies is not deterministic, DO NOT USE IT if you can help it.
#
# Perform fake build to make a fixed-output derivation out of the dependencies required for build.
# Afterwards build with ('maven.repo.local' must be writable so copy it out of nix store):
# mvn package --offline -Dmaven.repo.local=$(cp -dpR ${deps}/.m2 ./ && chmod +w -R .m2 && pwd)/.m2
{ stdenv, maven }:

{ src
, sha256
, nativeBuildInputs ? [ maven ]
, mavenFlags ? ""
, ...
}@args:

stdenv.mkDerivation ({
name = if args ? name then "${args.name}-maven-deps"
else if args ? pname && args ? version then "${args.pname}-${args.version}-maven-deps"
else "maven-deps";

inherit src nativeBuildInputs;

buildPhase = ''
while mvn package -Dmaven.repo.local=$out/.m2 ${mavenFlags} -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/.m2 -type f -regex '.+\(\.lastUpdated\|resolver-status\.properties\|_remote\.repositories\)' -delete'';
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = sha256;
} // (removeAttrs args ["name" "pname" "version"]))
25 changes: 4 additions & 21 deletions pkgs/development/tools/global-platform-pro/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{ stdenv, fetchFromGitHub, jdk, maven, makeWrapper, jre_headless, pcsclite }:
{ stdenv, fetchFromGitHub, fetchMavenDeps, jdk, maven, makeWrapper, jre_headless, pcsclite }:

# TODO: This is quite a bit of duplicated logic with gephi. Factor it out?
stdenv.mkDerivation rec {
pname = "global-platform-pro";
version = "18.09.14";
Expand All @@ -13,25 +12,9 @@ stdenv.mkDerivation rec {
sha256 = "1vws6cbgm3mrwc2xz9j1y262vw21x3hjc9m7rqc4hn3m7gjpwsvg";
};

deps = stdenv.mkDerivation {
name = "${pname}-${version}-deps";
inherit src;
nativeBuildInputs = [ jdk maven ];
installPhase = ''
# Download the dependencies
while ! mvn package "-Dmaven.repo.local=$out/.m2" -Dmaven.wagon.rto=5000; do
echo "timeout, restart maven to continue downloading"
done

# And keep only *.{pom,jar,sha1,nbm} and delete all ephemeral files
# with lastModified timestamps inside
find "$out/.m2" -type f \
-regex '.+\(\.lastUpdated\|resolver-status\.properties\|_remote\.repositories\)' \
-delete
'';
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = "1qwgvz6l5wia8q5824c9f3iwyapfskljhqf1z09fw6jjj1jy3b15";
deps = fetchMavenDeps {
inherit pname version src;
sha256 = "1qwgvz6l5wia8q5824c9f3iwyapfskljhqf1z09fw6jjj1jy3b15";
};

nativeBuildInputs = [ jdk maven makeWrapper ];
Expand Down
22 changes: 6 additions & 16 deletions pkgs/servers/exhibitor/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ fetchFromGitHub, maven, jdk, makeWrapper, stdenv, ... }:
{ fetchFromGitHub, fetchMavenDeps, maven, jdk, makeWrapper, stdenv, ... }:
stdenv.mkDerivation rec {
pname = "exhibitor";
version = "1.5.6";
Expand All @@ -9,21 +9,11 @@ stdenv.mkDerivation rec {
sha256 = "07vikhkldxy51jbpy3jgva6wz75jksch6bjd6dqkagfgqd6baw45";
rev = "5fcdb411d06e8638c2380f7acb72a8a6909739cd";
};
mavenDependenciesSha256 = "00r69n9hwvrn5cbhxklx7w00sjmqvcxs7gvhbm150ggy7bc865qv";
# This is adapted from https://github.com/volth/nixpkgs/blob/6aa470dfd57cae46758b62010a93c5ff115215d7/pkgs/applications/networking/cluster/hadoop/default.nix#L20-L32
fetchedMavenDeps = stdenv.mkDerivation {
name = "exhibitor-${version}-maven-deps";
inherit src nativeBuildInputs;
buildPhase = ''
cd ${pomFileDir};
while timeout --kill-after=21m 20m mvn package -Dmaven.repo.local=$out/.m2; [ $? = 124 ]; do
echo "maven hangs while downloading :("
done
'';
installPhase = ''find $out/.m2 -type f \! -regex '.+\(pom\|jar\|xml\|sha1\)' -delete''; # delete files with lastModified timestamps inside
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = mavenDependenciesSha256;

fetchedMavenDeps = fetchMavenDeps {
inherit pname version src nativeBuildInputs;
configurePhase = "cd ${pomFileDir}";
sha256 = "00r69n9hwvrn5cbhxklx7w00sjmqvcxs7gvhbm150ggy7bc865qv";
};

# The purpose of this is to fetch the jar file out of public Maven and use Maven
Expand Down
2 changes: 2 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ in

fetchMavenArtifact = callPackage ../build-support/fetchmavenartifact { };

fetchMavenDeps = callPackage ../build-support/fetch-maven-deps.nix { };

prefer-remote-fetch = import ../build-support/prefer-remote-fetch;

global-platform-pro = callPackage ../development/tools/global-platform-pro/default.nix { };
Expand Down