From f63e764bb6bf636ddcdfb841072cdc4ef3712135 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Sun, 21 Jun 2015 22:24:03 -0400 Subject: [PATCH] Add buildMaven --- pkgs/build-support/build-maven.nix | 58 ++++++++++++++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 ++ 2 files changed, 60 insertions(+) create mode 100644 pkgs/build-support/build-maven.nix diff --git a/pkgs/build-support/build-maven.nix b/pkgs/build-support/build-maven.nix new file mode 100644 index 000000000000..bde95080e745 --- /dev/null +++ b/pkgs/build-support/build-maven.nix @@ -0,0 +1,58 @@ +{ stdenv, maven, runCommand, writeText, fetchurl, lib }: +/* Takes an info file generated by mvn2nix + * (https://github.com/shlevy/mvn2nix-maven-plugin) and builds the maven + * project with it. + * + * repo: A local maven repository with the project's dependencies. + * + * settings: A settings.xml to pass to maven to use the repo. + * + * build: A simple build derivation that uses mvn compile and package to build + * the project. + */ +infoFile: let + info = builtins.fromJSON (builtins.readFile infoFile); + + repo = runCommand "maven-repository" {} '' + ${lib.concatStrings (map (dep: let + inherit (dep) url sha1 groupId artifactId version; + + fetch = fetchurl { inherit url sha1; }; + in '' + dir=$out/$(echo ${groupId} | sed 's|\.|/|g')/${artifactId}/${version} + mkdir -p $dir + ln -sv ${fetch} $dir/${fetch.name} + '') info.dependencies)} + ''; + + settings = writeText "settings.xml" '' + + ${repo} + + ''; + + src = dirOf infoFile; +in { + inherit repo settings; + + build = stdenv.mkDerivation { + name = "${info.project.artifactId}-${info.project.version}.jar"; + + src = builtins.filterSource (path: type: + (toString path) != (toString (src + "/target")) && + (toString path) != (toString (src + "/.git")) + ) src; + + buildInputs = [ maven ]; + + buildPhase = "mvn --offline --settings ${settings} compile"; + + installPhase = '' + mvn --offline --settings ${settings} package + mv target/*.jar $out + ''; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index c6d6a9791856..94a6d6740ac7 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -280,6 +280,8 @@ let runScript = args.runScript; }; + buildMaven = callPackage ../build-support/build-maven.nix {}; + dotnetenv = import ../build-support/dotnetenv { inherit stdenv; dotnetfx = dotnetfx40;