Managing Gradle deps.json across multiple Nixpkgs versions

I’ve been working on packaging Cogfly (a mod manager for Hollow Knight: Silksong), which is written in Java and uses Gradle as a build system. In testing, a deps.json file generated for one channel will not work with another channel. The only difference between the deps files are the version of the Kotlin standard library in use (2.4.0 on nixos-unstable vs 2.3.0 on nixos-26.05).

So far, I’ve just built the dependencies once for each channel and renamed the files as needed. I could also probably try to determine which channel is in use and rely on that, but that feels error-prone. I could also regenerate the deps file each build, but that feels wasteful. Does anyone know how to get the deps file to work across channels or have suggestions for how to manage different deps files in an elegant way?

I’ve included the package.nix and flake.nix files I’ve used to build Cogfly below. To regenerate the deps.json file, I run nix build .#cogfly.mitmCache.updateScript && ./result.

package.nix

{
  makeWrapper,
  runCommand,
  stdenv,
  fetchFromGitHub,
  pkgs,
  lib,
  nix-update-script,
}:
stdenv.mkDerivation (finalAttrs: {
  pname = "Cogfly";
  version = "1.2.5";

  src = fetchFromGitHub {
    owner = "Nix-main";
    repo = "Cogfly";
    tag = "${finalAttrs.version}";
    hash = "sha256-noOe0Jyb53swzloY7e1TWI6oYzOpQclrTU38/R5mvXk=";
  };

  nativeBuildInputs = with pkgs; [
    gradle_9
    makeWrapper
  ];

  buildInputs = with pkgs; [
    zenity
  ];

  desktopItem = pkgs.makeDesktopItem {
    name = "Cogfly";
    desktopName = "Cogfly";
    exec = "cogfly";
    icon = "cogfly";
    type = "Application";
    categories = [
      "Utility"
    ];
    mimeTypes = [
      "x-scheme-handler/cogfly"
    ];
  };

  mitmCache = pkgs.gradle.fetchDeps {
    pkg = finalAttrs.finalPackage;
    data = ./deps.json;
  };

  strictDeps = true;
  __structuredAttrs = true;
  __darwinAllowLocalNetworking = true;

  gradleFlags = [
    "-Dorg.gradle.java.home=${pkgs.jdk25}"
  ];

  gradleBuildTask = "shadowJar";

  doCheck = true;

  installPhase = ''
    mkdir -p $out/bin
    cp build/libs/${finalAttrs.pname}-${finalAttrs.version}.jar $out/bin

    makeWrapper ${lib.getExe pkgs.temurin-jre-bin-25} $out/bin/cogfly \
      --add-flags "-jar $out/bin/${finalAttrs.pname}-${finalAttrs.version}.jar" \
      --prefix PATH : ${lib.makeBinPath [ pkgs.zenity ]}

    install -m 644 -D -t $out/share/applications $desktopItem/share/applications/*

    install -m 444 -D resources/icons/icon.png $out/share/icons/cogfly
    install -m 444 -D resources/icons/icon.png $out/share/icons/hicolor/128x128/apps/cogfly.png
  '';

  passthru.updateScript = nix-update-script { };

  meta = {
    description = "Cross-platform mod manager for Hollow Knight: Silksong";
    homepage = "https://github.com/Nix-main/Cogfly";
    changelog = "https://github.com/Nix-main/Cogfly/releases/tag/${finalAttrs.version}";
    license = lib.licenses.gpl3Only;
    maintainers = with lib.maintainers; [
      abus-sh
    ];
    mainProgram = "cogfly";
    platforms = [
      "x86_64-linux"
    ];
  };
})

flake.nix

{
  description = "A very basic flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
    #nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-26.05";
    #nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-25.11";
  };

  outputs = inputs: {
    packages = builtins.mapAttrs (system: pkgs: {
      cogfly = pkgs.callPackage ./package.nix { };

      default = inputs.self.packages.${system}.cogfly;
    }) inputs.nixpkgs.legacyPackages;
  };
}
1 Like