Help with custom maven package build phase

Hello,

I’m trying to package this program (afirma-simple) for my own personal use (altough if there were more people interested in it I wouldn’t mind preparing a PR for nixpkgs and officially maintaining it).

The problem I find myself running into is the software needs to run mvn clean install -Denv=install to build the actual application, but the buildMavenPackage only exposes the installPhase. When I tried using either mvnParameters or mvnDepsParameters I got an error telling me that dependencies couldn’t be fetched in offline mode, and weren’t previously fetched. Any advice would be greatly appreciated, as I searched the discourse, and the web, read the Maven package on nixpkgs docs and also the code, and cannot figure this out.

This is the code for the derivation:

{pkgs, ...}:
with pkgs;
  maven.buildMavenPackage rec {
    pname = "afirma";
    version = "1.8.2";
    owner = "ctt-gob-es";
    repo = "clienteafirma";
    rev = "v${version}";

    mvnHash = "sha256-znP3PVl/NP9m5oszIUIpqF1gDoT8JF/gwjVZSu7K2l0=";
    mvnJdk = pkgs.jdk11;
    doCheck = false;

    nativeBuildInputs = [
      makeWrapper
    ];

    installPhase = ''
      mkdir -p $out/usr/{bin,lib,share}

      echo "#!/bin/bash\njava -Djdk.tls.maxHandshakeMessageSize=65536 -jar /usr/lib/AutoFirma/AutoFirma.jar "$@"" > autofirma

      install -Dm644 autofirma $out/usr/bin/autofirma

      mkdir -p $out/usr/lib/firefox/defaults/pref
      install -Dm644 afirma-simple-installer/linux/instalador_deb/src/etc/firefox/pref/AutoFirma.js \
        $out/usr/lib/firefox/defaults/pref/autofirma.js

      mkdir -p $out/usr/share/java/autofirma
      install -Dm644 afirma-simple/target/AutoFirma.jar \
        $out/usr/share/java/autofirma/autofirma.jar

      mkdir -p $out/usr/share/pixmaps
      install -Dm644 afirma-simple-installer/linux/instalador_deb/src/usr/share/AutoFirma/AutoFirma.svg \
        $out/usr/share/pixmaps/autofirma.svg

      mkdir -p $out/usr/share/application
      install -Dm644 afirma-simple-installer/linux/instalador_deb/src/usr/share/applications/afirma.desktop \
        $out/usr/share/applications/autofirma.desktop

      mkdir -p $out/usr/share/licenses
      install -Dm644 afirma-simple-installer/linux/instalador_deb/src/usr/share/doc/common-licenses \
          $out/usr/share/licenses/autofirma

      makeWrapper ${jdk}/bin/java $out/usr/bin/autofirma \
        --add-flags "-jar $out/share/java/autofirma/autofirma.jar"
    '';

    src = fetchFromGitHub {
      inherit owner;
      inherit repo;
      inherit rev;
      sha256 = "sha256-YtGtTeWDWwCCIikxs6Cyrypb0EBX2Q2sa3CBCmC6kK8=";
    };

    meta = with lib; {
      license = licenses.bsd3;
    };
  }

I tried your build and it worked for me, I just had to add mvnParameters = "-Denv=install";, replace

mvnHash = "sha256-CR3Xt5jqnlja4dEjicZvuYKZLPFiznA9+OqiRltRA3E=";

and

install -Dm644 afirma-simple-installer/linux/instalador_deb/src/usr/share/common-licenses/* \
    $out/usr/share/licenses

Perhaps you changed something in the dependency fetching parameters and forgot to update the mvnHash?

Also I’d suggest installing to $out/bin rather than $out/usr/bin.

You are right, it does! I don’t know where that old mvnHash came from. Thank you very much!

If you change anything related to the hash in the build, you have to ensure to blank out the hashes (i.e. set to the empty string), rebuild, check the error for the correct hash, then continue.