Maven hash mismatch between nix-build and nixpkgs-review

Hello i am creating a package for tinymediamanager

Here is my PR

The commit that i reference (in case i force push): tinyMediaManager: init at 5.3.0 · NixOS/nixpkgs@0bed87f · GitHub

For local development i have a default.nix file so that i can use nix-build to test changes in package.nix

default.nix
let
  pkgs = import <nixpkgs> {};
in
pkgs.callPackage ./package.nix {}
package.nix
{
  alsa-lib,
  autoPatchelfHook,
  chromedriver,
  copyDesktopItems,
  deno,
  ffmpeg,
  fontconfig,
  fetchFromGitLab,
  glib,
  gtk3,
  imagemagick,
  lib,
  libmediainfo,
  libzen,
  libx11,
  libxext,
  libxft,
  libxi,
  libxrender,
  libxtst,
  makeDesktopItem,
  makeWrapper,
  maven,
  pipewire,
  wayland,
  yt-dlp,
  zenity,
  zlib,
  stdenv,
  xz,
}:

let
  # Define sources for different architectures
  sources = {
    "x86_64-linux" = {
      arch = "amd64";
    };
    "aarch64-linux" = {
      arch = "arm64";
    };
  };

  # Select the source based on the current system
  sysSrc =
    sources.${stdenv.hostPlatform.system}
      or (throw "Unsupported system: ${stdenv.hostPlatform.system}");

  runtimeLibs = [
    alsa-lib
    fontconfig
    glib
    gtk3
    libmediainfo
    libzen
    pipewire
    wayland
    libx11
    libxext
    libxft
    libxi
    libxrender
    libxtst
    zlib
  ];

  runtimepaths = [
    chromedriver
    yt-dlp
    ffmpeg
    deno
    zenity
  ];
in
maven.buildMavenPackage rec {
  pname = "tinyMediaManager";
  version = "5.3.0";

  # hash for nix-build
  # mvnHash = "sha256-bf5GSlZgFvNBE7yVF/CasLBOQoaqgDKyX+OmDCVVuuc=";
  # hash for nixpkgs-review rev HEAD
  # mvnHash = "sha256-EkoJHjdgBYH821T3/yvTQFhU1uTtipqiBp+gFwJdUEE=";
  mvnHash = "sha256-bf5GSlZgFvNBE7yVF/CasLBOQoaqgDKyX+OmDCVVuuc=";
  
  src = fetchFromGitLab {
    owner = "tinyMediaManager";
    repo = "tinyMediaManager";
    rev = "tinyMediaManager-${version}";
    hash = "sha256-chvr+EvZO84ln6YmHxtVSrxXXf9G7xlmJGSyzS/ItfQ=";
  };

  # remove other builds from pom.xml to speed up build
  postPatch = ''
    substituteInPlace pom.xml \
      --replace-fail "<descriptor>src/assembly/windows-x64.xml</descriptor>" ""
  '';

  # Fetch plugins during the dependency download phase.
  mvnDepsParameters = "-DskipTests -Pdist -DbuildNumber=${version} -Dmaven.buildNumber.skip=true";
  mvnParameters = "-DskipTests -Pdist -DbuildNumber=${version} -Dmaven.buildNumber.skip=true";

  nativeBuildInputs = [
    autoPatchelfHook
    copyDesktopItems
    makeWrapper
    imagemagick
    xz
  ];
  buildInputs = runtimeLibs;

  strictDeps = true;
  __structuredAttrs = true;

  desktopItems = [
    (makeDesktopItem {
      name = "tinyMediaManager";
      exec = "tinyMediaManager";
      icon = "tinyMediaManager";
      comment = "A media management tool";
      desktopName = "tinyMediaManager";
      genericName = "Media Manager";
      categories = [
        "Video"
        "AudioVideo"
      ];
      terminal = false;
    })
  ];

  installPhase = ''
    runHook preInstall

    TARBALL="dist/tinyMediaManager-${version}-GIT-linux-${sysSrc.arch}.tar.gz"
    if [ ! -f "$TARBALL" ]; then
      echo "Error: Could not find $TARBALL"
      echo "Actual contents of dist/ directory:"
      ls -R dist/ || echo "dist/ directory not found"
      exit 5
    fi

    # Create destination directory
    mkdir -p $out/opt/tinyMediaManager $out/bin

    # --strip-components=1 removes the top-level folder inside the tarball
    # so files land directly in our share directory.
    tar -xvf "$TARBALL" -C $out/opt/tinyMediaManager --strip-components=1

    # maven downloads an unfree binary
    makeWrapper $out/opt/tinyMediaManager/tinyMediaManager $out/bin/tinyMediaManager \
      --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath runtimeLibs}" \
      --prefix PATH : "${lib.makeBinPath runtimepaths}"


    # Handle the icon
    mkdir -p $out/share/pixmaps
    if [ -f "$out/opt/tinyMediaManager/tmm.png" ]; then
        ln -s $out/opt/tinyMediaManager/tmm.png $out/share/pixmaps/tinyMediaManager.png
    fi

    for size in 16 32 48 64 128; do
      mkdir -p $out/share/icons/hicolor/"$size"x"$size"/apps
      magick -background none $out/share/pixmaps/tinyMediaManager.png -resize "$size"x"$size" $out/share/icons/hicolor/"$size"x"$size"/apps/tinyMediaManager.png
    done

    # change startup settings
    # suppress autoupdate
    # it should use PATH and not shipped binaries
    substituteInPlace $out/opt/tinyMediaManager/launcher.yml \
    --replace-fail 'jvmOpts:' "jvmOpts:
      - '-Dtmm.noupdate=true'
      - '-Dtmm.useexternaltools=false'"


    runHook postInstall
  '';

  meta = with lib; {
    description = "A media management tool";
    homepage = "https://www.tinymediamanager.org/";
    changelog = "https://gitlab.com/tinyMediaManager/tinyMediaManager/-/releases/tinyMediaManager-${version}#changelog";
    # the java code is open source but the binary which invokes the java code is unfree
    # maven downloads this unfree binary
    # the creator said that in the future it could be possible that building from source no longer works when he integrates stronger drm
    # the creator allowed redistributing
    license =
      with lib.licenses;
      AND [
        asl20
        unfreeRedistributable
      ];
    maintainers = with lib.maintainers; [ gamebeaker ];
    platforms = [
      "x86_64-linux"
      "aarch64-linux"
    ];
    mainProgram = "tinyMediaManager";
  };
}

My problem is that with nix-build my maven hash is:

mvnHash = "sha256-bf5GSlZgFvNBE7yVF/CasLBOQoaqgDKyX+OmDCVVuuc=";

When i use nixpkgs-review rev HEAD the hash changes to:

mvnHash = "sha256-EkoJHjdgBYH821T3/yvTQFhU1uTtipqiBp+gFwJdUEE=";

The code is in Line 80

I tried deleting my maven cache.
I thought maybe nixpkgs-review builds the arm version so i made the hashes system depended.

Why does this happen?

Hmmmm I’ve seen this before with go. Setting proxyVendor = true usually fixes it. I don’t know the java ecosystem well enough to know if there’s an equivalent?

I don’t know go.
In java i need to pin the exact version number for all dependencies. It looks like it somehow inferred a dependency and nix-build inferred another version than nixpkgs-review idk why.

I missed it as the dependency wasn’t explicitly stated in pom.xml
The missing dependency:

<pluginManagement>
             <plugins>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-resources-plugin</artifactId>
+                    <version>3.5.0</version>
+                </plugin>
1 Like

Disclaimer: I might be conflating things – and this might not be your issue! But, it seems related at least?

I had thought the maven fetcher was nondeterministic. Derivations using maven are not deterministic · Issue #25686 · NixOS/nixpkgs · GitHub this is the earliest issue I could find about it. I had been finding the hash will frequently need changing even though there has been seemingly no source changes? I didn’t get to the bottom of why. There’s a bunch of examples of this happening here: Pull requests · NixOS/nixpkgs · GitHub . And an issue I opened about it here Build failure: fetchedMavenDeps · Issue #480108 · NixOS/nixpkgs · GitHub

@jrestivo i think it is related i had a look in the nixpkgs manual and there is a section that describes my problem. (At least i think that was my problem)

tldr: maven in nixpkgs got updated so the “default” plugin version from Core plugins changed to the newer version. Now the hash isn’t the same anymore as the used plugins changed.

Here is a list of the core plugins from maven: Available Plugins – Maven

You need to specify the version of the core plugins in pom.xml or you will have this problem each time the maven version changes.

I used the plugin described in the manual and got this feedback from maven:


Now i know which plugins and version i need to add via the patch file.

1 Like

If I recall correctly, maven merges the project pom.xml with the “maven installation” pom.xml (containing the versions of the “default” plugins"). You can get the result for yourself with mvn help:effective-pom.