Merge pull request #100634 from fzakaria/faridzakaria/buildmaven-nix

buildMaven: Update buildMaven to pure Nix

authored by Shea Levy and committed by GitHub ee7722a7 56f935ef

+46 -39
+46 -39
pkgs/build-support/build-maven.nix
··· 1 - { stdenv, maven, runCommand, writeText, fetchurl, lib, requireFile }: 2 - /* Takes an info file generated by mvn2nix 3 - * (https://github.com/NixOS/mvn2nix-maven-plugin) and builds the maven 4 - * project with it. 5 - * 6 - * repo: A local maven repository with the project's dependencies. 7 - * 8 - * settings: A settings.xml to pass to maven to use the repo. 9 - * 10 - * build: A simple build derivation that uses mvn compile and package to build 11 - * the project. 12 - */ 13 - infoFile: let 14 info = lib.importJSON infoFile; 15 16 - script = writeText "build-maven-repository.sh" '' 17 - ${lib.concatStrings (map (dep: let 18 inherit (dep) sha1 groupId artifactId version metadata repository-id; 19 - 20 versionDir = dep.unresolved-version or version; 21 authenticated = dep.authenticated or false; 22 url = dep.url or ""; 23 24 - fetch = if (url != "") then ((if authenticated then requireFile else fetchurl) { 25 - inherit url sha1; 26 - }) else ""; 27 28 fetchMetadata = (if authenticated then requireFile else fetchurl) { 29 inherit (metadata) url sha1; 30 }; 31 - in '' 32 - dir=$out/$(echo ${groupId} | sed 's|\.|/|g')/${artifactId}/${versionDir} 33 - mkdir -p $dir 34 35 - ${lib.optionalString (fetch != "") '' 36 - ln -sv ${fetch} $dir/${fetch.name} 37 - ''} 38 - ${lib.optionalString (dep ? metadata) '' 39 - ln -svf ${fetchMetadata} $dir/maven-metadata-${repository-id}.xml 40 - ${lib.optionalString (fetch != "") '' 41 - ln -sv ${fetch} $dir/$(echo ${fetch.name} | sed 's|${version}|${dep.unresolved-version}|') 42 - ''} 43 - ''} 44 - '') info.dependencies)} 45 - ''; 46 47 - repo = runCommand "maven-repository" {} '' 48 - bash ${script} 49 - ''; 50 51 settings = writeText "settings.xml" '' 52 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" ··· 65 name = "${info.project.artifactId}-${info.project.version}.jar"; 66 67 src = builtins.filterSource (path: type: 68 - (toString path) != (toString (src + "/target")) && 69 - (toString path) != (toString (src + "/.git")) 70 - ) src; 71 72 buildInputs = [ maven ]; 73
··· 1 + { stdenv, maven, runCommand, writeText, fetchurl, lib, requireFile, linkFarm }: 2 + # Takes an info file generated by mvn2nix 3 + # (https://github.com/NixOS/mvn2nix-maven-plugin) and builds the maven 4 + # project with it. 5 + # 6 + # repo: A local maven repository with the project's dependencies. 7 + # 8 + # settings: A settings.xml to pass to maven to use the repo. 9 + # 10 + # build: A simple build derivation that uses mvn compile and package to build 11 + # the project. 12 + # 13 + # @example 14 + # project = pkgs.buildMaven ./project-info.json 15 + infoFile: 16 + let 17 info = lib.importJSON infoFile; 18 19 + dependencies = lib.flatten (map (dep: 20 + let 21 inherit (dep) sha1 groupId artifactId version metadata repository-id; 22 versionDir = dep.unresolved-version or version; 23 authenticated = dep.authenticated or false; 24 url = dep.url or ""; 25 26 + fetch = if (url != "") then 27 + ((if authenticated then requireFile else fetchurl) { 28 + inherit url sha1; 29 + }) 30 + else 31 + ""; 32 33 fetchMetadata = (if authenticated then requireFile else fetchurl) { 34 inherit (metadata) url sha1; 35 }; 36 37 + layout = "${ 38 + builtins.replaceStrings [ "." ] [ "/" ] groupId 39 + }/${artifactId}/${versionDir}"; 40 + in lib.optional (url != "") { 41 + layout = "${layout}/${fetch.name}"; 42 + drv = fetch; 43 + } ++ lib.optionals (dep ? metadata) ([{ 44 + layout = "${layout}/maven-metadata-${repository-id}.xml"; 45 + drv = fetchMetadata; 46 + }] ++ lib.optional (fetch != "") { 47 + layout = "${layout}/${ 48 + builtins.replaceStrings [ version ] [ dep.unresolved-version ] 49 + fetch.name 50 + }"; 51 + drv = fetch; 52 + })) info.dependencies); 53 54 + repo = linkFarm "maven-repository" (lib.forEach dependencies (dependency: { 55 + name = dependency.layout; 56 + path = dependency.drv; 57 + })); 58 59 settings = writeText "settings.xml" '' 60 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" ··· 73 name = "${info.project.artifactId}-${info.project.version}.jar"; 74 75 src = builtins.filterSource (path: type: 76 + (toString path) != (toString (src + "/target")) && (toString path) 77 + != (toString (src + "/.git"))) src; 78 79 buildInputs = [ maven ]; 80