I have a working NixOS config (25.11) and I tried to add my own package to my flake.nix. It’s not my first package but I’m still new to NixOS, so I came up with this (with some AI assistance):
{
lib,
stdenvNoCC,
fetchurl,
makeWrapper,
jre,
}:
let
pname = "megameklab";
version = "0.50.11";
src = fetchurl {
url = "https://github.com/MegaMek/megameklab/releases/download/v${version}/megameklab-${version}.tar.gz";
hash = "sha256-1w70phkwk44hcs1lw20kfhq17lnshjrg8j644v7vdldyfn5djx41";
};
in
stdenvNoCC.mkDerivation {
inherit pname version src;
nativeBuildInputs = [ makeWrapper ];
dontBuild = true;
installPhase = ''
runHook preInstall
mkdir -p $out/share/${pname}
cp -R ./* $out/share/${pname}/
# ensure upstream launch script is executable
chmod +x $out/share/${pname}/bin/MegaMekLab
mkdir -p $out/bin
upstream_launcher="$out/share/${pname}/bin/MegaMekLab"
if [ ! -f "$upstream_launcher" ]; then
echo "Could not find upstream Gradle launcher script at: $upstream_launcher"
exit 1
fi
# Wrap the upstream script:
# - --set JAVA_HOME: makes the Gradle script find the correct java
# - --set JAVACMD: forces the exact java binary (robust even if JAVA_HOME logic changes)
# - --chdir: matches typical upstream invocation from the app root dir
makeWrapper "$upstream_launcher" "$out/bin/megameklab" \
--set JAVA_HOME "${jre}" \
--set JAVACMD "${jre}/bin/java" \
--chdir "$out/share/${pname}"
runHook postInstall
'';
meta = with lib; {
description = "MegaMekLab";
homepage = "https://github.com/MegaMek/megameklab";
license = licenses.gpl3;
platforms = platforms.all;
mainProgram = "megameklab";
};
}
However, when I try to build the package, the command just silently fails. It produces no output at all (except for the usual “dirty repo” warning):
nix --extra-experimental-features "nix-command flakes" build .#megameklab -L -v --show-trace --print-build-logs --print-out-paths --rebuild
warning: Git tree '/etc/nixos' is dirty
root nixos on master [+]
If I import the package into a module and run nixos-rebuild switch I get this error:
Command 'nix --extra-experimental-features 'nix-command flakes' build --print-out-paths '/etc/nixos#nixosConfigurations."nixvm".config.system.build.toplevel' --no-link' returned non-zero exit status 1.
I’ve already checked if the OOM killer has been involved (I had that issue in the past) but it isn’t the case. I’ve also tried to build the package on a real machine (instead of VM), but it failed there too.
I’ve tried all debug / verbose flags I could find, but after hundreds of lines of evaluating XXX the output abruptly ends without an error message (and exit code 1).
After I ran out of ideas, I tried to debug this with the help of GPT5.2 and aider. I was surprised how structured the AI approached the debugging (I had 0 expectations from past experiences) but after 2 hours I gave up. The only thing I found out is that nix exits very early in the build process, without printing any error message, but I still have no idea why.
How would you debug this?